CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-green

Green is a clean, colorful, fast python test runner.

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

Green's command-line interface provides comprehensive test running capabilities with extensive configuration options, multiple output formats, and integration with coverage tools.

Capabilities

Main Entry Point

The primary function for running Green from the command line, handling argument parsing, configuration merging, and test execution orchestration.

def main(argv=None, testing=False):
    """
    Main entry point for Green command-line interface.
    
    Args:
        argv (list, optional): Command-line arguments. If None, uses sys.argv.
                              Examples: ['tests/', '--verbose', '2'] 
        testing (bool): Enable testing mode which affects some behaviors like
                       coverage handling and output formatting. Defaults to False.
    
    Returns:
        int: Exit code - 0 for success (all tests passed), 
             non-zero for failure (test failures, errors, or runtime issues)
    
    Example:
        exit_code = main(['tests/', '--verbose', '2', '--run-coverage'])
        if exit_code == 0:
            print("All tests passed!")
    """

Internal Main Implementation

Internal implementation that handles the core logic of argument processing, configuration setup, and test runner initialization.

def _main(argv, testing):
    """
    Internal main implementation handling core CLI logic.
    
    Args:
        argv (list): Parsed command-line arguments
        testing (bool): Testing mode flag
    
    Returns:
        int: Exit code
    """

Usage Examples

Basic Command Line Usage

# Run all tests in current directory
green

# Run tests in specific directory
green tests/

# Run specific test file
green tests/test_module.py

# Run specific test class
green tests.test_module.TestClass

# Run specific test method
green tests.test_module.TestClass.test_method

Verbose Output Options

# Minimal output (dots only)
green -q tests/

# Standard output 
green tests/

# Verbose output (show test names)
green -v tests/

# More verbose (show docstrings when available)
green -vv tests/

# Most verbose (show file locations)
green -vvv tests/

Coverage Integration

# Run tests with coverage reporting
green --run-coverage tests/

# Coverage with custom config file
green --run-coverage --coverage-config-file .coveragerc tests/

# Coverage with omit patterns
green --run-coverage --omit-patterns "*/tests/*,*/venv/*" tests/

Output Formats

# Generate JUnit XML report
green --junit-report results.xml tests/

# Disable colored output
green --no-color tests/

# Disable Windows-specific formatting
green --disable-windows tests/

Parallel Execution Control

# Use specific number of processes
green --processes 4 tests/

# Use single process (disable parallel execution)
green --processes 1 tests/

# Let Green auto-detect optimal process count (default)
green tests/

Configuration Files

# Use specific config file
green --config myconfig.cfg tests/

# Show location of shell completion file
green --completion-file

# Get shell completions for test targets
green --completions tests/test_

Debug and Development

# Enable debug output
green --debug tests/

# More debug information
green --debug --debug tests/

# Keep temporary files for debugging
green --keep-reports tests/

# Show Green version information
green --version

Configuration File Examples

Green supports configuration files in multiple locations with precedence rules:

~/.green (global configuration)

verbose = 2
run-coverage = True
processes = 4

setup.cfg (project-level)

[green]
verbose = 1
omit-patterns = */tests/*,*/migrations/*
junit-report = test-results.xml

.green (directory-level)

verbose = 3
keep-reports = True
debug = True

Shell Integration

Bash/Zsh Completion Setup

# Add to ~/.bashrc or ~/.zshrc
which green >& /dev/null && source "$( green --completion-file )"

Environment Variables

# Specify custom config file location
export GREEN_CONFIG=/path/to/custom/green.cfg

# Then run Green normally
green tests/

Exit Codes

Green returns standard exit codes for integration with CI/CD systems:

  • 0: All tests passed successfully
  • 1: Test failures occurred
  • 2: Test errors occurred
  • 3: Configuration or runtime errors
  • 130: Interrupted by user (Ctrl+C)

Integration Examples

CI/CD Pipeline Usage

# GitHub Actions example
- name: Run tests with Green
  run: |
    green --junit-report test-results.xml --run-coverage tests/
    
- name: Upload test results
  uses: actions/upload-artifact@v2
  with:
    name: test-results
    path: test-results.xml

Makefile Integration

test:
	green --verbose 2 tests/

test-coverage:
	green --run-coverage --verbose 2 tests/

test-ci:
	green --junit-report junit.xml --run-coverage --verbose 1 tests/

Install with Tessl CLI

npx tessl i tessl/pypi-green

docs

cli.md

configuration.md

django-integration.md

index.md

junit-xml.md

output-formatting.md

setuptools-integration.md

test-execution.md

test-loading.md

test-results.md

tile.json