Testing is a critical part of CPython development. This guide covers running the test suite, interpreting results, and writing new tests.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/python/cpython/llms.txt
Use this file to discover all available pages before exploring further.
Running Tests
Basic Test Run
Run the entire test suite:By default, tests are prevented from overusing resources like disk space and memory.
Resource-Intensive Tests
To run tests that use more resources (like the buildbots do):Running Specific Tests
Single Test Module
Run a specific test file:Multiple Test Modules
Run several specific tests:With Make
You can also use make with theTESTOPTS variable:
Test Options
Verbose Output
Get detailed output for debugging:Running Failed Tests
If tests fail, re-run them in verbose mode:Common Test Options
Understanding Test Output
Successful Test
Skipped Test
Failed Test
Test with Errors
Debug Builds and Testing
When testing with a debug build (--with-pydebug):
Special Build Testing
Reference Counting Tests
WithPy_REF_DEBUG enabled (included in --with-pydebug):
Trace References
For deep reference debugging:Running Test Subsets
By Category
By Pattern
Writing Tests
Test File Structure
Create test files inLib/test/:
Using Test Support
Thetest.support module provides utilities:
C Extension Tests
For testing C API:Continuous Integration
CPython uses multiple CI systems:GitHub Actions
View build status:- GitHub Actions
- Runs on Linux, macOS, and Windows
- Tests multiple configurations
Azure Pipelines
View build status:- Azure DevOps
- Additional platform coverage
Reporting Test Failures
If tests fail and it appears to be a CPython problem:Verify it's not your environment
- Try a clean build
- Check system dependencies
- Test on a different platform if possible
File a bug report
Visit github.com/python/cpython/issues and include:
- CPython version/commit
- Platform and OS version
- Verbose test output
- Steps to reproduce
Troubleshooting
Tests are too slow
Tests are too slow
Use parallel testing:Or run fewer tests:
Random test failures
Random test failures
Some tests can be flaky. Try:If it’s consistently flaky, report it as a bug.
Out of memory errors
Out of memory errors
Some tests use significant memory. Either:
- Run tests individually
- Use
make testinstead ofmake buildbottest - Skip memory-intensive tests
Permission errors in tests
Permission errors in tests
Some tests require specific permissions. Run with appropriate access or skip those tests:
