You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python/includes/vs-2019/unit-testing-python.md
+14-13Lines changed: 14 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -15,22 +15,22 @@ ms.workload:
15
15
16
16
## Select the test framework for a Python project
17
17
18
-
Visual Studio supports two testing frameworks for Python, [unittest](https://docs.python.org/3/library/unittest.html) and [pytest](https://pytest.org/en/latest/) (available in Visual Studio 2019 starting with version 16.3). By default, no framework is selected when you create a Python project. To specify a framework, right-click on the project name in Solution Explorer and select the **Properties** option. This opens the project designer, which allows you to configure tests through the **Test** tab. From this tab, you can select the test framework that you want to use for your project.
18
+
Visual Studio supports two testing frameworks for Python, [unittest](https://docs.python.org/3/library/unittest.html) and [pytest](https://pytest.org/en/latest/) (available in Visual Studio 2019 starting with version 16.3). By default, no framework is selected when you create a Python project. To specify a framework, right-click on the project name in Solution Explorer and select the **Properties** option. This action opens the project designer, which allows you to configure tests through the **Test** tab. From this tab, you can select the test framework that you want to use for your project.
19
19
20
-
- For the **unittest** framework, the project's root directory is used for test discovery. This location, as well as the text pattern for identifying tests, can be modified on the **Test** tab to user specified values.
21
-
- For the **pytest** framework, testing options such as test location and filename patterns are specified using the standard pytest .ini configuration file. See the [pytest reference documentation](https://docs.pytest.org/en/latest/reference.html#ini-options-ref) for more details.
20
+
- For the **unittest** framework, the project's root directory is used for test discovery. This location along with the text pattern for identifying tests can be modified on the **Test** tab to user specified values.
21
+
- For the **pytest** framework, testing options such as test location and filename patterns are specified using the standard pytest .ini configuration file. For more information, see the [pytest reference documentation](https://docs.pytest.org/en/latest/reference.html#ini-options-ref).
22
22
23
-
Once you've saved your framework selection and settings, test discovery is initiated in the Test Explorer. If the Test Explorer window is not already open, navigate to the toolbar and select **Test** > **Test Explorer**.
23
+
After you save your framework selection and settings, test discovery is initiated in the Test Explorer. If the Test Explorer window isn't already open, navigate to the toolbar and select **Test** > **Test Explorer**.
24
24
25
25
## Configure testing for Python without a project
26
26
27
-
Visual Studio allows you to run and test existing Python code without a project, by [opening a folder](../../quickstart-05-python-visual-studio-open-folder.md) with Python code. Under these circumstances, you'll need to use a **PythonSettings.json** file to configure testing.
27
+
Visual Studio allows you to run and test existing Python code without a project, by [opening a folder](../../quickstart-05-python-visual-studio-open-folder.md) with Python code. Under these circumstances, you need to use a **PythonSettings.json** file to configure testing.
28
28
29
29
1. Open your existing Python code using the **Open a Local Folder** option.
30
30
31
31

32
32
33
-
1. Within the Solution Explorer window, click the **Show All Files** icon to show all files in the current folder.
33
+
1. Within the Solution Explorer window, select the **Show All Files** icon to show all files in the current folder.
34
34
35
35

36
36
@@ -59,20 +59,21 @@ Visual Studio allows you to run and test existing Python code without a project,
59
59
}
60
60
```
61
61
62
-
1. Save your changes to the PythonSettings.json file to initiate test discovery for the specified framework.
62
+
1. Save your changes to the PythonSettings.json file, which initiates test discovery for the specified framework.
63
+
63
64
> [!Note]
64
65
> If the Test Explorer window is already open **CTRL** + **R,A** also triggers discovery.
65
66
66
67
## Discover and view tests
67
68
68
-
By default, Visual Studio identifies **unittest** and **pytest** tests as methods whose names start with `test`. To see test discovery, do the following:
69
+
By default, Visual Studio identifies **unittest** and **pytest** tests as methods whose names start with `test`. To see test discovery, follow these steps:
69
70
70
71
1. Open a [Python project](../../managing-python-projects-in-visual-studio.md).
71
72
72
73
1. Once the project is loaded in Visual Studio, right-click your project in Solution Explorer and select the **unittest** or **pytest** framework from the Properties **Test** tab.
73
74
74
75
> [!Note]
75
-
> If you use the pytest framework, you can specify test location and filename patterns using the standard pytest .ini configuration file. By default, the workspace/project folder is used, with a pattern of `test_*py` and `*_test.py`. See the [pytest reference documentation](https://docs.pytest.org/en/latest/reference.html#ini-options-ref) for more details.
76
+
> If you use the pytest framework, you can specify test location and filename patterns using the standard pytest .ini configuration file. By default, the workspace/project folder is used, with a pattern of `test_*py` and `*_test.py`. For more information, see the [pytest reference documentation](https://docs.pytest.org/en/latest/reference.html#ini-options-ref).
76
77
77
78
1. After the framework is selected, right-click the project again and select **Add** > **New Item**, then select **Python Unit Test** followed by **Add**.
78
79
@@ -91,7 +92,7 @@ By default, Visual Studio identifies **unittest** and **pytest** tests as method
91
92
92
93
1. Save the file if necessary, then open **Test Explorer** with the **Test** > **Test Explorer** menu command.
93
94
94
-
1.**Test Explorer** searches your project for tests and displays them as shown below. Double-clicking a test opens its source file.
95
+
1.**Test Explorer** searches your project for tests and displays them as shown in the following image. Double-clicking a test opens its source file.
95
96
96
97

97
98
@@ -105,13 +106,13 @@ For more information on the `unittest` module and writing tests, see the [Python
105
106
106
107
## Run tests
107
108
108
-
In **Test Explorer** you can run tests in a variety of ways:
109
+
In **Test Explorer** you can run tests in various ways:
109
110
110
111
-**Run All** clearly runs all shown tests (subject to filters).
111
112
- The **Run** menu gives you commands to run failed, passed, or not run tests as a group.
112
113
- You can select one or more tests, right-click, and select **Run Selected Tests**.
113
114
114
-
Tests run in the background and**Test Explorer** updates each test's status as it completes:
115
+
Tests run in the background.**Test Explorer** updates each test's status as it completes:
115
116
116
117
- Passing tests show a green tick and the time taken to run the test:
117
118
@@ -125,7 +126,7 @@ Tests run in the background and **Test Explorer** updates each test's status as
125
126
126
127
## Debug tests
127
128
128
-
Because unit tests are pieces of code, they are subject to bugs just like any other code and occasionally need to be run in a debugger. In the debugger you can set breakpoints, examine variables, and step through code. Visual Studio also provides diagnostic tools for unit tests.
129
+
Because unit tests are pieces of code, they're subject to bugs just like any other code and occasionally need to be run in a debugger. In the debugger you can set breakpoints, examine variables, and step through code. Visual Studio also provides diagnostic tools for unit tests.
129
130
130
131
> [!Note]
131
132
> By default, test debugging uses the ptvsd 4 debugger for Visual Studio 2017 (versions 15.8 and later) and debugpy for Visual Studio 2019 (versions 16.5 and later). If you would like to instead use ptvsd 3, you can select the **Use Legacy Debugger** option on **Tools** > **Options** > **Python** > **Debugging**.
0 commit comments