Repository navigation
Error running test with pytest #4334
Copy link
Copy link
Closed
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
Issue Type: Bug
I have a simple test scenario which yields some errors in vs code. I'm trying to run the following little program with the Python extension:
import os
import shutil
def test_something():
assert True == False
def setup_module(module):
""" setup any state specific to the execution of the given module."""
os.mkdir(".tmp")
os.chdir(".tmp")
def teardown_module(module):
""" teardown any state that was previously setup with a setup_module
method.
"""
os.chdir("../")
shutil.rmtree(".tmp")
I get the following two errors:
cannot open file:///home/erikah/ok/plattform/test/test_something.py. Detail: File not found (file:///home/erikah/ok/plattform/test/test_something.py)
This path seems to be wrong, given that the path to the program is /home/erikah/ok/plattform/python_testing/test
There was an error in running the tests.
Running the test in the command line I get the following:
$ python3 -m pytest
================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.6.7, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
rootdir: /home/erikah/ok/plattform/python_testing, inifile:
plugins: pylama-7.6.6
collected 1 item
test/test_something.py F [100%]
======================================================================================================================================== FAILURES ========================================================================================================================================
_____________________________________________________________________________________________________________________________________ test_something _____________________________________________________________________________________________________________________________________
def test_something():
> assert True == False
E assert True == False
../test/test_something.py:6: AssertionError
================================================================================================================================ 1 failed in 0.04 seconds ================================================================================================================================
Extension version: 2019.1.0
VS Code version: Code 1.31.0 (7c66f58312b48ed8ca4e387ebd9ffe9605332caa, 2019-02-06T08:51:24.856Z)
OS version: Linux x64 4.15.0-45-generic
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (8 x 2700) |
| GPU Status | 2d_canvas: enabled checker_imaging: disabled_off flash_3d: enabled flash_stage3d: enabled flash_stage3d_baseline: enabled gpu_compositing: enabled multiple_raster_threads: enabled_on native_gpu_memory_buffers: disabled_software rasterization: disabled_software surface_synchronization: enabled_on video_decode: unavailable_off webgl: enabled webgl2: enabled |
| Load (avg) | 1, 1, 1 |
| Memory (System) | 31.12GB (12.10GB free) |
| Process Argv | --unity-launch |
| Screen Reader | no |
| VM | 0% |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Activity
erihanse commentedon Feb 8, 2019
Btw., running python 3.6.7.
Another example, also failing:
erihanse commentedon Feb 8, 2019
Seems like I get the following when I use the command "run all unit tests".
erihanse commentedon Feb 8, 2019
erihanse commentedon May 6, 2019
I'm still experiencing this.

When using fixtures, where I run tests with temporary directories for instance, this happens.
magicandcode commentedon Nov 18, 2019
I just ran into the same or a similar issue. Running the tests again via the tests button in the bottom status bar seems to (at least temporarily) have solved the problem.
RomanKornev commentedon Jan 10, 2020
I'm getting the same error despite passing tests:
Bug keeps appearing and disappearing.
Log:
2 remaining items
brettcannon commentedon Jul 24, 2020
We are going through old issues and we noticed that no one from the team had replied to this issue. I want to apologize for the oversight and to let you know that the issue was reviewed by the team and triaged (as shown by the labels applied to this issue).
Almenon commentedon Jul 29, 2020
is this issue related to #12403 by any chance?
brettcannon commentedon Jul 29, 2020
Almenon (@Almenon) I believe they are different issues.
ianhco commentedon Aug 21, 2020
Still experiencing in vscode:
python 3.8
vscode 1.48
Fixed by Re-Discovering the tests
WilliamDidier commentedon Jan 28, 2021
Same issue :
I believe it was caused by a test previously discovered, then commented and that was trying to be run through "Run all tests" button.
As stated in the above comment, re-descovering the tests fixed the problem.
A message a little more explicit that "Illegal value for
line" would be appreciated thoughmichjnich commentedon Feb 10, 2021
I'm getting this now I think, and no matter what I do I can't get it working.
In VS code I configure "Cwd" as "src", since that's where the source code for my Django project is. root dir contains all the config files, docker stuff etc.
With "src" in place, test explorer shows the tests, but they can't run. Without it, nothing is found.
If I run the tests with "src" set as cwd, I get an error telling me it couldn't find
project/path/src/src/rest/of/tests/test_model.py- i.e.. thesrchas been applied twice somehow.I've removed
.pytest_cache, restarted VSC, rediscovered things, in every possible order, but can't get rid of this.At the moment, I'm resorting to running my tests manually outside of VS Code. Any news on this issue?
shacker commentedon Mar 18, 2021
Just encountered the same issue. Simple test passes from Terminal, but fails with this error in VSCode. Running "Rediscover all tests" fixes it.
rvanlaar commentedon May 11, 2021
I ran into the same error. The path it was searching for was wrong.
What happened was that my pycache files were originally in another directory (due to docker mounts). Removing the all the pycaches resolved the issue:
find ./ -name "__pycache__" -exec rm -rf {} \+eleanorjboyd commentedon Oct 30, 2023
Hello! I have reviewed this issue and given the architectural changes of the testing rewrite, this issue should no longer exist on the rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself!
To use the rewrite yourself just add
”python.experiments.optInto": ["pythonTestAdapter"]to your user settings. You can confirm you have the rewrite enabled by setting your log level to trace, via theDeveloper: Set Log Levelcommand in the command palette. Then check to see ifExperiment 'pythonTestAdapter' is activeis in your python logs.Thanks!