Green is a clean, colorful, fast python test runner.
—
Green's command-line interface provides comprehensive test running capabilities with extensive configuration options, multiple output formats, and integration with coverage tools.
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 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
"""# 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# 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/# 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/# 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/# 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/# 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_# 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 --versionGreen supports configuration files in multiple locations with precedence rules:
verbose = 2
run-coverage = True
processes = 4[green]
verbose = 1
omit-patterns = */tests/*,*/migrations/*
junit-report = test-results.xmlverbose = 3
keep-reports = True
debug = True# Add to ~/.bashrc or ~/.zshrc
which green >& /dev/null && source "$( green --completion-file )"# Specify custom config file location
export GREEN_CONFIG=/path/to/custom/green.cfg
# Then run Green normally
green tests/Green returns standard exit codes for integration with CI/CD systems:
# 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.xmltest:
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