Python run configurations
This topic summarizes the run configurations available for Python. Each table provides keys that are available within a run configuration and their descriptions.
python
Runs Python scripts.
(required) | Specifies the configuration type |
(required) | Specifies the configuration name displayed in the Run & Debug window |
Either file or module is required | Specifies the path to the Python script to be executed To execute a module, use |
Either module or file is required | Specifies the name of the module to be executed To execute a Python script, use |
| Specifies the arguments that will be passed to the script or module |
| Custom environment variables for the process in the form of a JSON object. To define an environment variable, add a property, where the key is the variable name and the value is the value of the variable, for example:
"environment": {
"PYTHONUNBUFFERED": "1",
"PYTHONWARNINGS": "ignore"
}
|
| Names of other configurations which will be executed before this configuration, for example: |
| Working directory for this run configuration. |
| When set to |
Example
The following configuration runs script.py passing
60
as the argument:{ "type": "python", "name": "run_script", "module": "script", "arguments": ["60"], }
python-tests
Runs Python tests by using either pytest or unittest testing framework.
(required) | Specifies the configuration type |
(required) | Specifies the configuration name displayed in the Run & Debug window |
(required) | Specifies the testing framework. Possible values are:
|
| Specifies the type of the
|
(required) | Specifies the tests to be executed. Depending on the value of
|
| Lists the command-line options to be passed to the testing framework. For the full list of available command-line options, refer to: |
| Custom environment variables for the process in the form of a JSON object. To define an environment variable, add a property, where the key is the variable name and the value is the value of the variable, for example:
"environment": {
"PYTHONUNBUFFERED": "1",
"PYTHONWARNINGS": "ignore"
}
|
| Names of other configurations which will be executed before this configuration, for example: |
| Working directory for this run configuration. |
| When set to |
Examples
The following configuration uses pytest to run the tests in test_car.py and the tests directory. The
-k not brake
argument specifies that only the methods that don't contain "brake" in their names should be executed.{ "type": "python-tests", "name": "pytest", "testFramework": "pytest", "targetType": "path", "targets": ["test_car.py", "tests"], "arguments": ["-k not brake"], }The following configuration uses unittest to run the tests in tests/test_car.py. The
--failfast
argument specifies that the testing should be stopped on the first failure.{ "type": "python-tests", "name": "unittest", "testFramework": "unittest", "targetType": "path", "targets": ["tests/test_car.py"], "arguments": ["--failfast"], }