I want to integrate PyTest
with Visual Studio
so my tests show up in the Test Explorer. So far I have not found any way to do this while some old posts here suggest that people have done it before. As far as I can tell, as this article suggests, someone should develop an adapter interface for PyTest. However, other posts like this show that others were successful in getting this to work. But these two have not worked for me so far. Is there a way to get this working?

- 8,764
- 15
- 64
- 91
-
1Did you try this: https://donjayamanne.github.io/pythonVSCodeDocs/docs/unittests/ ? – Felippe Raposo Feb 20 '18 at 22:38
-
4That is for VSCode which is a different product that Visual Studio – Barka Feb 21 '18 at 18:14
-
1https://github.com/Microsoft/PTVS/issues/1847 – denfromufa Feb 27 '18 at 14:23
-
I am not sure if it helps, but you can [produce test results from py.test tests in junit format](https://stackoverflow.com/questions/29123840/how-to-generate-test-report-using-pytest) and I noticed there [is junit runner/wrapper for visual studio](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test) – running.t Jul 02 '18 at 11:08
-
Whats the project type you are work in , is it Flask, Django or Just Pure python ? – not 0x12 Jul 23 '18 at 04:10
-
In Visual Studio 2017 -- I noticed that I had to install python3.6 and then have it install using the requirements.txt file, which installs the pytest plugin. Somehow python3.9 has some restrictions, hence the need for going back to python3.6 and get the pytest plugin to work. – serup Aug 20 '21 at 13:21
3 Answers
Support for Pytest in Visual Studio has been added on Visual Studio 2019 (16.3 Preview 2)
You have to change your project's test framework by right-clicking it and going to Properties -> Test
You can add a pytest.ini to your project to configure pytest further.
More info from MS themselves: https://devblogs.microsoft.com/python/whats-new-for-python-in-visual-studio-16-3-preview-2/

- 3,632
- 1
- 17
- 31
first you have to Ensure that pytest has been installed in the currently configured python environment. And then you have to configure it like following: Command line options for the pytest can be passed by adding the necessary options into the following section in the user or workspace settings file settings.json: Add the options as individual items as shown below:
"python.unitTest.pyTestArgs": [
"--exitfirst",
"--verbose"
],
Plz tell me if it is working well

- 21
- 1
First install Pytes in your local machine. If your visula studio is already integrated with Python and if your test is also used Pytest then you dont need to worry,your visual studion will use Pytest.