question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pytest test discovery does not work with repository

See original GitHub issue

Environment 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14

github_iconTop GitHub Comments

1reaction
karrtikrcommented, Apr 19, 2019

Thanks. So it seems you are not using pytest command line to run these tests, if pytest CLI supports running such tests, and we are not, then we could consider this as a bug. For now this is a possible enhancement.

1reaction
chdsbdcommented, Apr 18, 2019

I’ve made a smaller repo here: https://github.com/chdsbd/vscode-python-test-discovery-repro

test_hello_world.py is runnable but test_add.py doesn’t work.

Screen Shot 2019-04-18 at 6 16 47 PM

Running poetry run pytest in backend/ will run all of the tests.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found