Skip to content

Commit e4eaabf

Browse files
authored
python testing doc update
1 parent aeb2cc3 commit e4eaabf

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

docs/python/testing.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-py
1616

1717
(If you're already familiar with unit testing, you can skip to the [walkthroughs](#example-test-walkthroughs).)
1818

19-
A **unit** is a specific piece of code to be tested, such as a function or a class. **Unit tests** are then other pieces of code that specifically exercise the code unit with a full range of different inputs, including boundary and edge cases.
19+
A **unit** is a specific piece of code to be tested, such as a function or a class. **Unit tests** are then other pieces of code that specifically exercise the code unit with a full range of different inputs, including boundary and edge cases. Both the unittest and pytest frameworks can be used to write unit tests.
2020

2121
For example, say you have a function to validate the format of an account number that a user enters in a web form:
2222

@@ -88,15 +88,15 @@ With this code, you can experience working with tests in VS Code as described in
8888

8989
## Configure tests
9090

91-
Once you have the Python extension installed and a Python file open within the editor, a test beaker icon will be displayed on the VS Code Activity bar. The beaker icon is for the **Test Explorer** view. When opening the Test Explorer, you will see a **Configure Tests** button if you don't have a test framework enabled. Once you select **Configure Tests**, you will be prompted to select a test framework and a folder containing the tests. If you're using unittest, you will also be asked to select the file glob pattern used to identify your test files.
91+
Once you have the Python extension installed and a Python file open within the editor, a test beaker icon will be displayed on the VS Code Activity bar. The beaker icon is for the **Test Explorer** view. When opening the Test Explorer, you will see a **Configure Tests** button if you don't have a test framework enabled. Once you select **Configure Tests**, you will be prompted to select a test framework and a folder containing the tests. If you're using unittest, you will also be asked to select the file glob pattern used to identify your test files. (a file glob pattern is a defined string pattern that matches file or folder names based on wildcards to then include or not include.)
9292

9393
![Configure Python Tests button displayed in the Test Explorer when tests haven't been configured.](images/testing/test-explorer-no-tests.png)
9494

95-
You can configure your tests anytime by using the **Python: Configure Tests** command from the [Command Palette](/docs/getstarted/userinterface.md#command-palette). You can also configure testing manually by setting either `python.testing.unittestEnabled` or `python.testing.pytestEnabled` to true. Each framework also has specific configuration settings as described under [Test configuration settings](#test-configuration-settings) for their folders and patterns.
95+
You can configure your tests anytime by using the **Python: Configure Tests** command from the [Command Palette](/docs/getstarted/userinterface.md#command-palette). You can also configure testing manually by setting either `python.testing.unittestEnabled` or `python.testing.pytestEnabled` which can be done either in the settings editor or in the `settings.json` file as described [here](https://code.visualstudio.com/docs/getstarted/settings). Each framework also has specific configuration settings as described under [Test configuration settings](#test-configuration-settings) for their folders and patterns.
9696

9797
If both frameworks are enabled, then the Python extension will only run `pytest`.
9898

99-
When you enable a test framework, VS Code prompts you to install the framework package if it's not already present in the currently activated environment:
99+
If you enable pytest, VS Code prompts you to install the framework package if it's not already present in the currently activated environment:
100100

101101
![VS Code prompt to install a test framework when enabled](images/testing/install-framework.png)
102102

@@ -116,6 +116,7 @@ class Test_TestIncrementDecrement(unittest.TestCase):
116116
def test_increment(self):
117117
self.assertEqual(inc_dec.increment(3), 4)
118118

119+
# This test is designed to fail for demonstration purposes.
119120
def test_decrement(self):
120121
self.assertEqual(inc_dec.decrement(3), 4)
121122

@@ -133,15 +134,16 @@ import inc_dec # The code to test
133134
def test_increment():
134135
assert inc_dec.increment(3) == 4
135136

137+
# This test is designed to fail for demonstration purposes.
136138
def test_decrement():
137139
assert inc_dec.decrement(3) == 4
138140
```
139141

140142
## Test discovery
141143

142-
By default, the Python extension attempts to discover tests once you enable a framework. You can trigger test discovery at any time using the **Test: Refresh Tests** command.
144+
By default, the Python extension attempts to discover tests once you enable a framework. You can also trigger test discovery at any time using the **Test: Refresh Tests** command from the command palette.
143145

144-
`python.testing.autoTestDiscoverOnSaveEnabled` is set to `true` by default, meaning that test discovery is also performed automatically whenever you add, delete, or update any Python file in the workspace. To disable this feature, set the value to `false`. You will need to reload the window for this setting to take effect.
146+
`python.testing.autoTestDiscoverOnSaveEnabled` is set to `true` by default, meaning that test discovery is also performed automatically whenever you add, delete, or update any Python file in the workspace. To disable this feature, set the value to `false` which can be done either in the settings editors or in the `settings.json` file as described [here](https://code.visualstudio.com/docs/getstarted/settings). You will need to reload the window for this setting to take effect.
145147

146148
Test discovery applies the discovery patterns for the current framework (which can be customized using the [Test configuration settings](#test-configuration-settings)). The default behavior is as follows:
147149

@@ -188,7 +190,7 @@ You can run tests using any of the following actions:
188190

189191
After a test run, VS Code displays results directly in the editor as gutter decorations. Failed tests will also be highlighted in the editor, with a Peek View that displays the test run error message and a history of all of the tests' runs. You can press `kbstyle(Escape)` to dismiss the view, and you can disable it by opening the User settings (**Preferences: Open Settings (UI)** command in the **Command Palette**) and changing the value of the **Testing: Automatically Open Peek View** setting to `never`.
190192

191-
In the **Test Explorer**, results are shown for individual tests and any classes and files containing those tests.
193+
In the **Test Explorer**, results are shown for individual tests and any classes and files containing those tests. Folders will display a failure icon if any of the tests within that folder did not pass.
192194

193195
![Test results on a unittest class and in Test Explorer](images/testing/test-results.png)
194196

@@ -231,7 +233,7 @@ Support for running tests in parallel with pytest is available through the `pyte
231233

232234
## Debug tests
233235

234-
You might occasionally need to step through and analyze tests in the debugger, either because the tests themselves have a code defect you need to track down or in order to better understand why an area of code being tested is failing.
236+
You might occasionally need to step through and analyze tests in the debugger, either because the tests themselves have a code defect you need to track down or in order to better understand why an area of code being tested is failing. For more information on debugging or to understand how it works in VS Code see [Python debugging configurations](/docs/python/debugging.md) and the general VS Code [Debugging](/docs/editor/debugging.md) article.
235237

236238
For example, the `test_decrement` functions given earlier are failing because the assertion itself is faulty. The following steps demonstrate how to analyze the test:
237239

@@ -283,11 +285,11 @@ For example, the configuration below in the `launch.json` file disables the `jus
283285

284286
If you have more than one configuration entry with `"purpose": ["debug-test"]`, the first definition will be used since we currently don't support multiple definitions for this request type.
285287

286-
For more information on debugging, see [Python debugging configurations](/docs/python/debugging.md) and the general VS Code [Debugging](/docs/editor/debugging.md) article.
287288

288289
## Test commands
289290

290-
Below are all the supported commands for testing with the Python extension in VS Code:
291+
Below are all the supported commandsfor testing with the Python extension in VS Code. These are all found via the command palette:
292+
291293
| Command Name | Description |
292294
| ------------ | ------------|
293295
| **Python: Configure Tests** | Configure the test framework to be used with the Python extension. |

0 commit comments

Comments
 (0)