简体   繁体   中英

How do I select a sub-folder as a directory containing tests in Python extension for Visual studio code

I am using VScode with python code and I have a folder with sub-directories (2-levels deep) containing python tests.

When I try "Python: Discover Tests" it asks for a test framework (selected pytest) and the directory in which tests exist. At this option, it shows only the top-level directories and does not allow to select a sub-directory.

I tried to type the directory path but it does not accept it.

Can someone please help on how to achieve this?

There are two options. One is to leave the selection as-is and make sure your directories are packages by adding __init__.py files as appropriate. The other is you can go into your workspace settings and adjust the "python.testing.pytestArgs" setting as appropriate to point to your tests.

Try opening the "Output" log (Ctrl+Shift+U) and run "Python: Discover Tests". Alternatively, you may type pytest --collect-only into the console. Maybe you are experiencing some errors with the tests themselves (such as importing errors).

Also, make sure to keep __init__.py file in your "tests" folder.

I am keeping the pytest "tests" folder within a subdirectory, and there are no issues with VS Code discovering the tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM