Run Single Test

Speed up testing by focusing on one test.

You're doing test-driven development (TDD) and you're in "the flow". Everything is clicking. Perhaps you want to focus on just one test:

  • Your tests take a while to run, and you don't want the slowdown of running them all

  • Some of your other tests are broken, or your current code breaks them

PyCharm makes it easy to select just one test to run. In fact, there are several ways to do it:

  • With the cursor anywhere in the test you want to focus on, right-click and choose to run that in the test runner

  • Right-click on the test in the test tool listing and choose to run it

The definition of "one test" is also flexible: one test function/method, an entire test class, an entire test file, or a directory. All can be right-clicked to focus on those tests.

What happens when you run one test? PyCharm creates a temporary run configuration, focused on just that test. This run configuration is based off the template run configurations, so if you want to put an environment variable on all your pytest single-tests configs, edit the pytest run configuration template.


Related Resources

Background on Testing
Background on Testing
Introduce testing, pytest, and how it all fits into PyCharm, along with a scenario to work on.
Unit Tests
Unit Tests
Write a simple test and run it in PyCharm's visual test runner.
Debugging During Testing
Debugging During Testing
When writing tests, use the PyCharm "visual debugger" to interactively poke around in the context of a problem.