Python

pytest CLI

pytest commands for Python test execution and configuration.

33 commands
Windows MacOS Linux
#testing #automation

Basic Execution

Run all tests in current directory recursively
pytest
Run all tests in a specific directory
pytest tests/
Run tests in a specific file
pytest tests/test_api.py
Run a specific test function
pytest tests/test_api.py::test_login
Run all tests in a specific class
pytest tests/test_api.py::TestClass
Stop on first failure
pytest -x
Stop after 3 failures
pytest --maxfail=3

Selection & Filtering

Run tests matching keyword expression
pytest -k "login and not admin"
Run tests with the slow marker
pytest -m slow
Collect and show tests without running
pytest --co
Rerun only tests that failed last time
pytest --lf
Run failures first then the rest
pytest --ff

Output & Reporting

Verbose output with test names
pytest -v
Extra verbose with full diffs
pytest -vv
Show print statements and stdout
pytest -s
Show short tracebacks on failure
pytest --tb=short
Disable tracebacks entirely
pytest --tb=no
Generate JUnit XML report
pytest --junit-xml=report.xml
Generate HTML report with pytest-html
pytest --html=report.html

Fixtures

Show all available fixtures
pytest --fixtures
Show fixtures in quiet mode
pytest --fixtures -q
Show setup and teardown of fixtures
pytest --setup-show

Markers

List all registered markers
pytest --markers
Exclude tests with the slow marker
pytest -m "not slow"
Run smoke or regression marked tests
pytest -m "smoke or regression"

Plugins

Disable the warnings plugin
pytest -p no:warnings
Run tests in parallel with pytest-xdist
pytest -n auto
Measure code coverage with pytest-cov
pytest --cov=mypackage
Generate HTML coverage report
pytest --cov=mypackage --cov-report=html
Set per-test timeout in seconds
pytest --timeout=30

Quick Commands

Run all tests with verbose output showing individual test names
pytest -v
Run tests matching a keyword expression for selective testing
pytest -k "login and not admin"
Run tests and measure code coverage for a specific package
pytest --cov=mypackage