-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Running test fails trying to access non-existing file #12403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also, when I try to set a breakpoint and debug the test, I get the following: ============================= test session starts ============================= =================================== ERRORS ==================================== 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. |
I cant downgrade right now wither, because I currently am affected by issue #99699 - |
New information - works with python 3.6, not with 3.7 or 3.8 |
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 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. |
We're still trying to figure out automatic conda activation - it's a very complicated problem, unfortunately. You can track that work via #5344. |
For the issue with |
Looks like this is a test runner issue then - I'm going to move it back into the extension repo. |
Understandable..... |
@tenspd137 Unfortunately, I am not able to reproduce the issue you see after running the file.
Can you please paste your Python test log output panel after you run the file? Also, please send a small reproducible example of the tests you're running, and also your settings. |
I have a repro of this, and potentially some extra info (ping me internally if you want to more interactively debug) I get this error message:
The interesting part here is my
Probably the best way to deal with this is to detect the absolute path, then fully resolve the workspace root ("realpath" equiv.) and recalculate the relative path. If it's still not within the workspace, then raise that as an error. Otherwise, you've found the file. Recalculating the relative path avoids opening the file in the editor twice, which is what will happen if you don't. |
@zooba Great guess. It seems this line is the one throwing the error. Right above the line we're resolving file path similar to how you described. Can you please paste your Python output panel & full Python test log output panel after you run the file?
I am not sure how opening the file comes into the picture. So do you get this error when opening the file (navigating a suite/function/file etc.)? Note the original issue reports the error on just running the file - not opening it. |
For instance, this is my Python test log,
Have a look at this string which appears in the traceback: In my case the following command was used to run the test file - which gives relative paths to root directory (Double check this with pytest-dev/pytest#7463)
What's the command you see in your Python output panel? Can you please try running the command in terminal and checking the output? Maybe Pytest returns absolute paths in case of mounted drives? |
Anyways, the fix seems clear enough. Don't expect only relative paths at this line and do a file exists check before opening document. |
I believe this is a duplicate of #10658 - both issues report the same bug with not being able to open a file and in the output both of the paths have a c at the end. Given that the other issues has more 👍 can we close this issue please? I can post @karrtikr 's comment on the other issue explaining how it needs to be fixed. |
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
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 However if XML file is generated under your project folder, there is another bug 😫 And it makes test runner to try to open So this junction point creates a link from |
+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. |
Wow, this was so incredibly obscure (for me). I've finally come up with a minimal way to reproduce this bug! Steps to reproduce
Method 1from datetime import datetime
def test_expected_behavior():
# Test fails, but fails in the way we expect both tests to fail
data_string = '2021'
format = '%Y-'
raise ValueError("time data %r does not match format %r" %
(data_string, format))
def test_unexpected_behavior():
# Test fails, but this time it causes the unexpected behavior in 12403
datetime.strptime('2021', '%Y-') Method 2 (uses a monkeypatch to isolate further than before)from datetime import datetime
class MockTime(datetime):
@classmethod
def strptime(cls, data_string, format):
raise ValueError("time data %r does not match format %r" %
(data_string, format))
def test_12403():
# Test fails, but fails in the way we expect (resolves bug)
# Comment this line out to reproduce 12403.
datetime = MockTime
datetime.strptime('2021', '%Y-')
|
I ran into the same error under linux. The path it was searching for was wrong. |
I have same error when running pytest. 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 |
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 The error occurs every time on windows, I've only managed to reproduce it in WSL once. |
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 |
I was able to reproduce this error using the stable build, and verified that #16769 will fix it 😊 |
The issue can still be reproduced with the steps in my previous comment: |
@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") |
@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. |
Using vscode-python 2020.6.88468
VSCode 1.46.0
When I run a test using the pytest framework, there is always an error at the end of the log:
Error: Error: cannot open file:///c%3A/Code/pixelcrunch/C. Detail: Unable to read file 'c:\Code\pixelcrunch\C' (Error: Unable to resolve non-existing file 'c:\Code\pixelcrunch\C')
regardless if the test itself actually passes or fails:
I don't know what is causing it to look for this file.
The text was updated successfully, but these errors were encountered: