You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Running test fails trying to access non-existing file #12403
=================================== ERRORS ====================================
____________ ERROR collecting pixelcrunch/tests/test_crunchers.py _____________
ImportError while importing test module 'C:\Code\pixelcrunch\pixelcrunch\tests\test_crunchers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
pixelcrunch_init_.py:13: in
import pandas as pd
C:\Miniconda3\envs\pychar2\lib\site-packages\pandas_init_.py:16: in
raise ImportError(
E ImportError: Unable to import required dependencies:
E numpy:
E
E IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
E
E Importing the numpy C-extensions failed. This error can happen for
E many reasons, often due to issues with your setup or how NumPy was
E installed.
E
E We have compiled some common reasons and troubleshooting tips at:
E
E https://numpy.org/devdocs/user/troubleshooting-importerror.html
E
E Please note and check the following:
E
E * The Python version is: Python3.8 from "C:\Miniconda3\envs\pychar2\python.exe"
E * The NumPy version is: "1.18.5"
E
E and make sure that they are the versions you expect.
E Please carefully study the documentation linked above for further help.
E
E Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I don't know what causes this. Importing pandas at the command line has no problems:
This happens on tests that pass or fail, regardless.
Works with python 3.8 if I run conda activate , cd to project folder, and start vscode using "code ." I wonder if it is ignoring some environment setup somehow? This is a workable solution for me, but not ideal. I'll leave it open since it isn't working as expected.
Which log do you see that error message (about file://) in?
The second issue might have something to do with conda environment not getting activated properly. Try activating it manually in an external terminal, and then launching VSCode from said terminal. If that doesn't help, can you please file a separate issue in https://github.com/microsoft/vscode-python/.
It shows up in the python test log. It happens after a test fails, and then doesn't seem to go away, even on tests that pass. If I start vscode and run a test that passes, I don't see it, until a test fails. Then it happens after every test.
Re: Conda environment - I have several - if I select the 3.6 one, there is no problem. It is python 3.7 or 3.8 where the issue arises. Again, starting vscode from terminal works, just not ideal.
It happens regardless on the first test that fails, and then the Error does not go away. Tests still report correctly as pass/fail in the panel, but it also shows:
So:
Vscode start
test that passes, no error
test that fails, error
test that passes, error
....
There is super-weird workaround (Windows 10) that I use now, hope this will be fixed in the repo soon.
But if you want to use pytest now, you can do the following.
Go to settings and add a line to Python > Testing: Pytest Args:
--junit-xml=./project-name-tests/results.xml
After that use elevated Power Shell to create a Junction from root of your disk to this subfolder:
cd /
New-Item -Type Junction -Path ./project-name-tests/ -Target .\Path\To\Working\Dir\project-name-tests\
What happens here?
I guess the main problem is that Windows paths are not detected correctly as absolute paths. So test runner tries to read C:\your\project\dir\C:\path\to\temp\file.xml and fails.
However if XML file is generated under your project folder, there is another bug 😫 And it makes test runner to try to open C:\subfolder\file.xml (I guess it's not always C: drive, but the drive you are using for your code).
So this junction point creates a link from C:\subfolder\ to C:\path\to\project\subfolder and the file is now readable even on incorrect path.
Update: I originally attributed my woes to a particular plugin I installed, but it's looking like that's unrelated. Still working on steps to easily reproduce.
Wow, this was so incredibly obscure (for me). I've finally come up with a minimal way to reproduce this bug!
Steps to reproduce
Install a fresh environment with pytest. I made a folder named vscode_python_12403 and used pipenv: pipenv install --dev pytest
Create a file, test_12403.py
Paste the following code into the file
Method 1
fromdatetimeimportdatetimedeftest_expected_behavior():
# Test fails, but fails in the way we expect both tests to faildata_string='2021'format='%Y-'raiseValueError("time data %r does not match format %r"%
(data_string, format))
deftest_unexpected_behavior():
# Test fails, but this time it causes the unexpected behavior in 12403datetime.strptime('2021', '%Y-')
Method 2 (uses a monkeypatch to isolate further than before)
fromdatetimeimportdatetimeclassMockTime(datetime):
@classmethoddefstrptime(cls, data_string, format):
raiseValueError("time data %r does not match format %r"%
(data_string, format))
deftest_12403():
# Test fails, but fails in the way we expect (resolves bug)# Comment this line out to reproduce 12403.datetime=MockTimedatetime.strptime('2021', '%Y-')
Click python interpreter on bottom-left and select the venv that pipenv generated
Configure tests.
a. Open command pallete with Ctrl+Shift+P
b. Enter Python: Configure Tests and click
c. Click pytest
d. Click . Root directory
Run tests and observe behavior.
Reacted by Anders, Diego Alloza González, John P. McConnell, soroshsabz, Benjamin Pinel and Kenneth Enevoldsen
I ran into the same error under linux. 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. Under linux I executed: find ./ -name "__pycache__" -exec rm -rf {} \+
I have same error when running pytest.
The tests are discoverable and I'm able to run them, but when I 'm running the test in output I see error: "cannot open file:///Users/yurib/Projects/files_uploader/tests/test_system_tests_linux.py"
Worth to mention that previously I moved the project to the new path and in the error vscode somehow refers to the old path of the test file. I tried to clear the cache, deleted python extension, but still same error.
====> MY ISSUE SOLVED by deleting cache files inside tests directory
import unittest
import unittest.mock
class TestCrash(unittest.TestCase):
def test_simple(self):
m2 = unittest.mock.Mock(name='mymock')
# m2() # no error if this is called
m2.assert_called()
Setup testrunner:
run command 'Python: Configure Tests'
select 'pytest'
select '. Root directory'
Run all tests
'There was an error running the tests' notification is displayed
'Python Test Log' output ends with an error message:
Error: Error: cannot open file:///d%3A/dev/py/1/c. Detail: Unable to read file 'd:\dev\py\1\c' (Error: Unable to resolve non-existing file 'd:\dev\py\1\c')
If I create the missing file ('d:\dev\py\1\c'), the error message is replaced:
Am also getting this error, seems to have not been resolved although it is reproducable and the issue was raised over a year ago. I guess I can go back to using test.http
rulerofthehuns the issue is still occurring on the stable version of the Python extension but it should be fixed in the next release. It's also now available in our insiders program (View > Command Palette... and run "Python: Switch to Insiders Weekly Channel")
Luciana Abud (@luabud) Thank you for the clarification. I've assumed the python extension was also updated with VSCode's update, and didn't check the version.
I can confirm that the bug cannot be reproduced with the new version.
Activity
tenspd137 commentedon Jun 17, 2020
Also, when I try to set a breakpoint and debug the test, I get the following:
============================= test session starts =============================
platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.8.2, pluggy-0.13.1
rootdir: c:\Code\pixelcrunch
collected 0 items / 1 error
=================================== ERRORS ====================================
____________ ERROR collecting pixelcrunch/tests/test_crunchers.py _____________
ImportError while importing test module 'C:\Code\pixelcrunch\pixelcrunch\tests\test_crunchers.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
pixelcrunch_init_.py:13: in
import pandas as pd
C:\Miniconda3\envs\pychar2\lib\site-packages\pandas_init_.py:16: in
raise ImportError(
E ImportError: Unable to import required dependencies:
E numpy:
E
E IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
E
E Importing the numpy C-extensions failed. This error can happen for
E many reasons, often due to issues with your setup or how NumPy was
E installed.
E
E We have compiled some common reasons and troubleshooting tips at:
E
E https://numpy.org/devdocs/user/troubleshooting-importerror.html
E
E Please note and check the following:
E
E * The Python version is: Python3.8 from "C:\Miniconda3\envs\pychar2\python.exe"
E * The NumPy version is: "1.18.5"
E
E and make sure that they are the versions you expect.
E Please carefully study the documentation linked above for further help.
E
E Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I don't know what causes this. Importing pandas at the command line has no problems:


This happens on tests that pass or fail, regardless.
tenspd137 commentedon Jun 17, 2020
I cant downgrade right now wither, because I currently am affected by issue #99699 -
microsoft/vscode#99699
tenspd137 commentedon Jun 17, 2020
New information - works with python 3.6, not with 3.7 or 3.8
tenspd137 commentedon Jun 17, 2020
Works with python 3.8 if I run conda activate , cd to project folder, and start vscode using "code ." I wonder if it is ignoring some environment setup somehow? This is a workable solution for me, but not ideal. I'll leave it open since it isn't working as expected.
int19h commentedon Jun 17, 2020
Which log do you see that error message (about
file://) in?The second issue might have something to do with conda environment not getting activated properly. Try activating it manually in an external terminal, and then launching VSCode from said terminal. If that doesn't help, can you please file a separate issue in https://github.com/microsoft/vscode-python/.
tenspd137 commentedon Jun 17, 2020
It shows up in the python test log. It happens after a test fails, and then doesn't seem to go away, even on tests that pass. If I start vscode and run a test that passes, I don't see it, until a test fails. Then it happens after every test.
tenspd137 commentedon Jun 17, 2020
Starting vscode from the directory after starting the environment fixes first problem. Still see file:// problem:

tenspd137 commentedon Jun 17, 2020
Re: Conda environment - I have several - if I select the 3.6 one, there is no problem. It is python 3.7 or 3.8 where the issue arises. Again, starting vscode from terminal works, just not ideal.
int19h commentedon Jun 17, 2020
We're still trying to figure out automatic conda activation - it's a very complicated problem, unfortunately. You can track that work via #5344.
int19h commentedon Jun 17, 2020
For the issue with
file://, does this only happen when debugging the test, or regardless of how you run it?tenspd137 commentedon Jun 17, 2020
It happens regardless on the first test that fails, and then the Error does not go away. Tests still report correctly as pass/fail in the panel, but it also shows:
So:
Vscode start
test that passes, no error
test that fails, error
test that passes, error
....
int19h commentedon Jun 17, 2020
Looks like this is a test runner issue then - I'm going to move it back into the extension repo.
21 remaining items
IBestuzhev commentedon Oct 14, 2020
There is super-weird workaround (Windows 10) that I use now, hope this will be fixed in the repo soon.
But if you want to use pytest now, you can do the following.
Go to settings and add a line to
Python > Testing: Pytest Args:After that use elevated Power Shell to create a Junction from root of your disk to this subfolder:
What happens here?
I guess the main problem is that Windows paths are not detected correctly as absolute paths. So test runner tries to read
C:\your\project\dir\C:\path\to\temp\file.xmland fails.However if XML file is generated under your project folder, there is another bug 😫 And it makes test runner to try to open
C:\subfolder\file.xml(I guess it's not always C: drive, but the drive you are using for your code).So this junction point creates a link from
C:\subfolder\toC:\path\to\project\subfolderand the file is now readable even on incorrect path.ChadBailey commentedon Jan 9, 2021
+1 for me, sadly.
Update: I originally attributed my woes to a particular plugin I installed, but it's looking like that's unrelated. Still working on steps to easily reproduce.
ChadBailey commentedon Jan 10, 2021
Wow, this was so incredibly obscure (for me). I've finally come up with a minimal way to reproduce this bug!
Steps to reproduce
vscode_python_12403and used pipenv:pipenv install --dev pytesttest_12403.pyMethod 1
Method 2 (uses a monkeypatch to isolate further than before)
a. Open command pallete with Ctrl+Shift+P
b. Enter
Python: Configure Testsand clickc. Click
pytestd. Click
. Root directoryrvanlaar commentedon May 11, 2021
I ran into the same error under linux. 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. Under linux I executed:
find ./ -name "__pycache__" -exec rm -rf {} \+yurigene commentedon Jul 5, 2021
I have same error when running pytest.
The tests are discoverable and I'm able to run them, but when I 'm running the test in output I see error: "cannot open file:///Users/yurib/Projects/files_uploader/tests/test_system_tests_linux.py"
Worth to mention that previously I moved the project to the new path and in the error vscode somehow refers to the old path of the test file. I tried to clear the cache, deleted python extension, but still same error.
====> MY ISSUE SOLVED by deleting cache files inside tests directory
rulerofthehuns commentedon Jul 14, 2021
Another way to reproduce:
Create test_main.py with contents:
Setup testrunner:
Run all tests
If I create the missing file ('d:\dev\py\1\c'), the error message is replaced:
Notes:
My testing environment:
VSCode: 1.58.1
pytest version: 6.2.4
python: 3.7.2
python extension: v2021.6.944021595
The error occurs every time on windows, I've only managed to reproduce it in WSL once.
Deleting pycache fixed WSL, no visible effect on windows.
MikeWise2718 commentedon Jul 25, 2021
Am also getting this error, seems to have not been resolved although it is reproducable and the issue was raised over a year ago. I guess I can go back to using
test.httpluabud commentedon Jul 29, 2021
I was able to reproduce this error using the stable build, and verified that #16769 will fix it 😊
rulerofthehuns commentedon Aug 6, 2021
The issue can still be reproduced with the steps in my previous comment:
#12403 (comment)
luabud commentedon Aug 6, 2021
rulerofthehuns the issue is still occurring on the stable version of the Python extension but it should be fixed in the next release. It's also now available in our insiders program (View > Command Palette... and run "Python: Switch to Insiders Weekly Channel")
rulerofthehuns commentedon Aug 8, 2021
Luciana Abud (@luabud) Thank you for the clarification. I've assumed the python extension was also updated with VSCode's update, and didn't check the version.
I can confirm that the bug cannot be reproduced with the new version.