October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Run Python Tests in PyCharm: A Practical Guide

Choose the runner installed in your project interpreter, launch tests from the gutter or Project view, and use the Test Runner tab to inspect results or collect coverage.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run Python tests in PyCharm, make sure the project uses the interpreter where your test framework is installed, choose the project’s default runner, then launch a test from the editor gutter or Project tool window. PyCharm opens the results in the Test Runner tab; you can run a single test or expand the target to a file, class, or directory.

1. Check the project interpreter and test framework

PyCharm’s test commands depend on the project interpreter and configured runner. First confirm the interpreter assigned to the project, then check that the framework your tests use is installed in that interpreter. For pytest, install pytest in the selected environment before choosing it as the runner. PyCharm detects installed runners; if none is selected or available, it uses unittest. See JetBrains’ pytest setup guide.

As an Amazon Associate I earn from qualifying purchases.

Use the framework the project already depends on rather than changing runners just to try a different option. PyCharm documents support for unittest, pytest, nose, tox, Twisted Trial, doctests, and several BDD frameworks, but the integration features vary; BDD framework support is marked as PyCharm Pro-only. The framework support overview is in JetBrains’ testing frameworks documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Set or verify the default runner

  1. Open Settings (on macOS, Preferences).
  2. Go to Python → Tools → Integrated Tools.
  3. Under Testing, select the project’s default test runner, such as pytest or unittest.

This setting is the default for new launches, not necessarily the runner for every test you already ran. An existing run/debug configuration associated with a file and framework can take precedence. If the expected runner is missing, check that it is installed in the project interpreter, then revisit the setting.

3. Run one test from the editor

Open a test file and use the gutter icon beside the test function or method. Select Run and the test name from the menu. You can also right-click the test in the editor and choose the run action from the context menu. PyCharm starts the test and displays its status and output in the Test Runner tab. These launch options and temporary configurations are covered in JetBrains’ Run tests documentation.

If no matching run/debug configuration exists, PyCharm creates a temporary one for the launch. That is convenient for a quick check; to reuse or customize the settings, save the configuration and edit it rather than relying on the temporary run.

4. Run a file, class, or directory

The same approach scales to a larger scope. Use the gutter or editor context menu to run a test file or class, or right-click the relevant test directory in the Project tool window and choose the run action. Select the target deliberately: a single test is faster for a focused check, while a directory run covers the tests grouped there.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a reusable pytest launch, open Run → Edit Configurations and create or select a pytest configuration. Its target can be a script, module, or custom target, and you can supply additional arguments. This is useful when you repeatedly run a particular subset or need pytest options. The available target and argument fields are described in JetBrains’ pytest run/debug configuration reference.

5. Read the Test Runner results

The Test Runner tab organizes results in a test tree, with status indicators that help you distinguish successful and failed tests. Expand the tree to locate a failure, then open the test from the result. The tab also provides test output and inline timing information, which can help identify where a run failed or which test took longer. JetBrains documents the result view in its Test Runner tab guide.

6. Debug pytest tests when needed

For a failing test that needs closer inspection, use the gutter or context-menu Debug action rather than Run. This launches the test under the debugger so you can step through execution and inspect values.

If pytest-cov interferes with debugging, JetBrains’ targeted workaround is to add --no-cov -s in the pytest configuration’s Additional Arguments. This is a troubleshooting option for that interaction, not a general requirement for pytest. See the pytest configuration reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

7. Collect test coverage

Coverage is a separate run mode. Select Run with Coverage from a run configuration, the Project tool window, or the editor’s run menu. PyCharm then displays coverage results alongside the test run. Coverage settings control how newly collected data is applied to active suites; consult JetBrains’ running tests with coverage guide and coverage settings reference if you need to change suite handling.

8. Optional: add checks or parallel execution

Run tests before committing

PyCharm documents test checks for Git and Mercurial commit workflows. If you want tests to run as part of committing, configure the relevant commit check in the IDE’s commit options. The exact controls depend on the version-control workflow you use; see JetBrains’ Run tests documentation.

Run pytest tests in parallel

For pytest projects, PyCharm documents parallel execution through pytest-xdist and an explicit worker count, using the argument -n <number of CPUs>. Install pytest-xdist in the project interpreter before using it. Parallel runs can consume more system resources, so they are an optional speed-up rather than a default requirement. Details are in the same Run tests guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.