Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PyTest working in Visual Studio

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?

like image 973
Barka Avatar asked Feb 17 '18 03:02

Barka


People also ask

How do I run a test in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.


2 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/

like image 96
Gabriel Cappelli Avatar answered Oct 04 '22 06:10

Gabriel Cappelli


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

like image 42
Karlos Dev Avatar answered Oct 04 '22 05:10

Karlos Dev