This extension allows you to run your Python Unittest or Pytest tests with the Test Explorer UI.
- Shows a Test Explorer in the Test view in VS Code's sidebar with all detected tests and suites and their state
- Shows a failed test's log when the test is selected in the explorer
- Supports multi-root workspaces
- Supports Unittest and Pytest test frameworks
- Install the extension
- Configure Python extension for Visual Studio Code to discover your tests (see Configuration section and documentation of a test framework of your choice (Unittest documentation, Pytest)
- Reload VS Code and open the Test view
- Run your tests using the icon in the Test Explorer
By default the extension uses the configuration from Python extension for Visual Studio Code. To configure Python for your project see Getting Started with Python in VS Code.
However, test framework used by this extension can be overridden by pythonTestExplorer.testFramework
configuration property.
Right now, the two available option are unittest
and pytest
. When property is set to null
, the configuration from Python extension is used.
List of currently used properties:
Property | Description |
---|---|
python.pythonPath |
Path to Python |
python.envFile |
Path to environment variable definitions file |
python.testing.cwd |
Optional working directory for unit tests |
python.testing.unittestEnabled |
Whether to enable or disable unit testing using unittest (enables or disables test discovery for Test Explorer) |
python.testing.unittestArgs |
Arguments used for test discovery (currently only -s and -p arguments are considered) |
python.testing.pyTestEnabled |
Whether to enable or disable unit testing using pytest (enables or disables test discovery for Test Explorer) |
python.testing.pyTestArgs |
Arguments passed to the pytest. Each argument is a separate item in the array. |
pythonTestExplorer.testFramework |
Test framework to use (overrides Python extension properties python.testing.unittestEnabled and python.testing.pyTestEnabled ) |
Configuration supports placeholders for workspace folder as ${workspaceFolder}
and environment variables in a form of ${env:YOUR_ENVIRONMENT_VARIABLE}
.
Whether no tests were discovered in the Test Explorer view or anything else doesn't work as expected, you can see logging output selecting Python Test Adapter Log
in the Output section.
- If you have any question or a problem with the extension, please file an issue.
- Contributions are always welcome! Please see contributing guide for more details.