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.

Test Discovery Fails - Reports as PyTest not installed

See original GitHub issue

Testing was working yesterday; I signed off around 4:45pm EST, got up this morning and encountered issues discovering and importing the packages from vscode. To me it appears as though the root of the workspace is not being added to the path.

Example: executing python -m pytest ETC from c:/projects/customers/CUSTOMERX/PROJECTX/ adds that to the path, specifying ./tests/ searches ./tests for tests and I can import the high level package from there. I feel as if the break is likely in this area.

Environment data

  • VS Code version: XXX Version: 1.35.1 (user setup) Commit: c7d83e57cd18f18026a8162d042843bda1bcf21f Date: 2019-06-12T14:30:02.622Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Windows_NT x64 10.0.17134

  • Extension version (available under the Extensions sidebar): 2019.6.22090 (25 June 2019)

  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda 2019.03 for Windows python version 3.6.8

  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A base

  • Relevant/affected Python packages and their versions: pytest

  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): Jedi enabled (output indicates it started jedi python language engine)

Expected behaviour

Discover Unit Tests - for example below works:

c:\projects\customers\CUSTOMERX\PROJECTX>python -m pytest --doctest-modules --junitxml=./tests/junit/test-results.xml --cov=./PACKAGEX/ ./tests/ --cov-report=xml:./tests/junit/coverage.xml --cov-report=html:./tests/junit/cov_html
================================================= test session starts =================================================
platform win32 -- Python 3.6.8, pytest-4.6.2, py-1.8.0, pluggy-0.12.0
rootdir: c:\projects\customers\CUSTOMERX\PACKAGEX, inifile: setup.cfg
plugins: arraydiff-0.3, cov-2.7.1, doctestplus-0.3.0, openfiles-0.3.2, remotedata-0.3.1
collected 14 items

tests\test_system_files.py ..                                                                                    [ 14%]

Actual behaviour

From the python test log (outputs) - Tried pytest 4.6.2, 4.6.3 and 4.4.1

python C:\Users\DrCrook\.vscode\extensions\ms-python.python-2019.6.22090\pythonFiles\testing_tools\run_adapter.py discover pytest -- -s --cache-clear c:\projects\customers\CUSTOMERX\PROJECTX
Test Discovery failed: 
Error: ============================= test session starts =============================
platform win32 -- Python 3.6.8, pytest-4.4.1, py-1.8.0, pluggy-0.12.0
rootdir: c:\projects\customers\CUSTOMERX\PROJECTX, inifile: setup.cfg
plugins: arraydiff-0.3, cov-2.7.1, doctestplus-0.3.0, openfiles-0.3.2, remotedata-0.3.1
collected 0 items / 9 errors

=================================== ERRORS ====================================
_________________ ERROR collecting tests/test_system_files.py _________________
ImportError while importing test module 'c:\projects\customers\CUSTOMERX\PROJECTX\tests\test_system_files.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests\test_system_files.py:6: in <module>
    from PACKAGEX.result import Result
E   ModuleNotFoundError: No module named 'PACKAGEX'

My folder structure:

/root
   /PACKAGEX
        /submoduleX
        /submoduleY
   /tests
        /helpers
        /test_submoduleX
        /test_submoduleY

.vscode/settings.json

{
    "python.testing.pytestArgs": [
    "--verbose",
    "--rootdir",
    "${workspaceFolder}",
    "${workspaceFolder}/tests"
    ],
    "python.testing.cwd": "${workspaceFolder}",
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe"
   }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
lukasz-migascommented, Jun 27, 2019

Same problem here. Downgrading to the previous version (2019.5.18875) fixes the problem.

1reaction
KsenoJivacommented, Jul 1, 2019

I noticed that the TestExplorer shows all Paths as lowercase. Therefore it could not find folders and modules within. In your case PACKAGEX might be uppercase too. Might there be a connection?

Read more comments on GitHub >

github_iconTop Results From Across the Web

VSCode pytest test discovery fails - python
It seems that when testing is universally enabled for all python projects and it fails to discover tests at the beginning, it fails...
Read more >
How to install and use plugins
If a plugin is installed, pytest automatically finds and integrates it, there is no need to activate it. Here is a little annotated...
Read more >
Pytest | PyCharm Documentation
PyCharm supports pytest, a fully functional testing framework. ... Rerun the test to evaluate the assert failing report:.
Read more >
pytest Documentation
More generally, pytest follows standard test discovery rules. ... (See Demo of Python failure reports with pytest). This allows you to use ...
Read more >
pytest-json-report
A pytest plugin to report test results as JSON files. ... hook although the plugin is not installed or not active (not using...
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