Pytest test discovery does not work with repository
See original GitHub issueEnvironment data
- VS Code version: 1.32.3
- Extension version (available under the Extensions sidebar): 2019.3.6215
- OS and version: Ubuntu 18.10
- Python version (& distribution if applicable, e.g. Anaconda): 3.6.3
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): Pipfile
- Relevant/affected Python packages and their versions: XXX
Expected behaviour
Test cases in src/tests are discovered and not in any other subdirectories of src
Actual behaviour
unable to discover any test or tests are not limited to src/tests
Steps to reproduce:
Python sources are in src directory , test cases are src/tests directory. I should be able to configure the unit test to be found in src/tests and in src/tests only.I’ve setup an .env so linter and intelli sense work, but this is not picked by unit test discovery.
Adding a __init__.py
to src seems so wrong as src is not a Python package and has the unwanted side effect that other subdirectories of src are also searched for tests
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:14
Top Results From Across the Web
VS Code not finding pytest tests - python - Stack Overflow
Tests are in a top-level subdirectory called test . Running pytest manually works. Share.
Read more >Good Integration Practices — pytest documentation
But now this introduces a subtle problem: in order to load the test modules from the tests directory, pytest prepends the root of...
Read more >Getting Started Unit Testing with Pytest - Towards Data Science
When we run our tests, pytest will perform a discovery process. The discovery process will scan the current folder and all of its...
Read more >Python Unit Testing - LSST DM Developer Guide
This page provides technical guidance to developers writing unit tests for DM's Python code base. See Software Unit Test Policy for an overview...
Read more >Testing Your Code - The Hitchhiker's Guide to Python
It is a good idea to implement a hook that runs all tests before pushing code to a shared repository. If you are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. So it seems you are not using
pytest
command line to run these tests, ifpytest
CLI supports running such tests, and we are not, then we could consider this as a bug. For now this is a possible enhancement.I’ve made a smaller repo here: https://github.com/chdsbd/vscode-python-test-discovery-repro
test_hello_world.py
is runnable buttest_add.py
doesn’t work.Running
poetry run pytest
inbackend/
will run all of the tests.