Skip to main content
Testing is a critical part of CPython development. This guide covers running the test suite, interpreting results, and writing new tests.

Running Tests

Basic Test Run

Run the entire test suite:
The test suite produces output showing which tests pass, fail, or are skipped. You can generally ignore messages about skipped tests due to optional features.
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 the TESTOPTS 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

This is normal if you haven’t installed the required dependencies.

Failed Test

A failure indicates a problem. Check the traceback for details.

Test with Errors

Crashes or core dumps indicate serious problems.

Debug Builds and Testing

When testing with a debug build (--with-pydebug):
This helps detect memory leaks - if the count increases without storing new objects, there’s likely a leak.

Special Build Testing

Reference Counting Tests

With Py_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 in Lib/test/:

Using Test Support

The test.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:

Reporting Test Failures

If tests fail and it appears to be a CPython problem:
1

Re-run in verbose mode

2

Verify it's not your environment

  • Try a clean build
  • Check system dependencies
  • Test on a different platform if possible
3

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

Use parallel testing:
Or run fewer tests:
Some tests can be flaky. Try:
If it’s consistently flaky, report it as a bug.
Some tests use significant memory. Either:
  • Run tests individually
  • Use make test instead of make buildbottest
  • Skip memory-intensive tests
Some tests require specific permissions. Run with appropriate access or skip those tests:

Test Coverage

Generate coverage reports:

Next Steps

Additional Resources