简体   繁体   中英

VS Code Python unittest “No tests ran”

I'm setting up python unit tests in VS Code using unittest, and running into some issues.

I am able to run my tests by selecting Run Tests from the status bar, and by right-clicking my test file in Explorer. When I do either of these, I see unit test output (eg "test_name ... ok" and "Ran 1 test in 0.002s") in the Python Test Log window, but I get a VS Code notification saying "No tests ran, please check the configuration settings for the tests." I am also not seeing the Run Test | Debug Test code lens in the test file.

I have followed the setup instructions in the VS Code docs here: https://code.visualstudio.com/docs/python/unit-testing , but I'm wondering if there are other steps I'll need to follow to get proper integration with the IDE?

I am using VS Code version 1.12.1, on Windows.

See unittest test discovery

Unittest supports simple test discovery. In order to be compatible with test discovery, all of the test files must be modules or packages (including namespace packages) importable from the top-level directory of the project (this means that their filenames must be valid identifiers).

I read the unittest Basic Example there is not something about make tests files to a module.
So that's Why you can see the Run Test | Debug Test code lens in the test Run Test | Debug Test code lens in the test file
But can't make test discovery discover it.

To make it to a module, you should create a __init__.py file in the same directory.

ps: for others who can't see Run Test | Debug Test Run Test | Debug Test code lens above the test, which means you can't make the unittest discover the single file as a test file.
Check the -p pattern maybe the right move.

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