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

Do you do enough testing? pytest to the rescue!
Join us to learn how you can use pytest to find bugs, improve code quality, and even have some fun along the way.
An Interview with Brian Okken - the pytest storyteller
Brian wears many hats including being a host for multiple Python podcasts and the author of Python Testing with pytest and has recently launched his new pytest course. Mostly, Brian spends his free time telling people they should write good, clean automated tests, specifically using pytest.
Productive pytest with PyCharm
Testing is a major part of Python development and pytest has become the leading testing framework. Brian Okken, author of the recent book Python Testing with pytest and host of the Test and Code podcast, helps you “level up” your pytest skill.