Skip to content
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

vscode-pytest unable to read testIds from temp file, file not created #24406

Closed
RamiAwar opened this issue Nov 8, 2024 · 15 comments · Fixed by #24798 or #24859
Closed

vscode-pytest unable to read testIds from temp file, file not created #24406

RamiAwar opened this issue Nov 8, 2024 · 15 comments · Fixed by #24798 or #24859
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.
Milestone

Comments

@RamiAwar
Copy link

RamiAwar commented Nov 8, 2024

I'm getting an error running Pytest on an individual test (using the Test Explorer).
It ends up running the entire test suite instead. Here are some more details. Was told to open this after finding a similar issue, but seems unconnected (#24307 (comment)).

Error[vscode-pytest]: unable to read testIds from temp file[Errno 2] No such file or directory: '/tmp/test-ids-e2faf2fe418633dcef80.txt'

I'm trying to run one test but it 'fails to detect the test ID'.

Note that I'm using devcontainers, with Python + Pylance + pytest explorer installed inside.

Also, not sure if relevant: I looked at /tmp/ but can't see any files named like this. I only see files named like python-test-discovery-698debb64df061b8b350.sock

LOGS:

2024-10-31 22:11:25.650 [info] Attempting to use temp directory for test ids file, file name: test-ids-750dd803c28e00398642.txt
env vars: "TEST_RUN_PIPE":"/tmp/python-test-results-59956af0fc8ae043f0d0.sock","RUN_TEST_IDS_PIPE":"/tmp/test-ids-750dd803c28e00398642.txt"}

2024-10-31 22:11:25.658 [info] Running pytest with arguments: /root/.vscode-server/extensions/ms-python.python-2024.16.1-linux-arm64/python_files/vscode_pytest/run_pytest_script.py --rootdir=/code/myproj

2024-10-31 22:11:25.658 [info] > /usr/local/bin/python ~/.vscode-server/extensions/ms-python.python-2024.16.1-linux-arm64/python_files/vscode_pytest/run_pytest_script.py --rootdir=.

2024-10-31 22:11:25.658 [info] cwd: .

At this point I see this in my test results:

Error[vscode-pytest]: unable to read testIds from temp file[Errno 2] No such file or directory: '/tmp/test-ids-750dd803c28e00398642.txt'

Python logs don't show anything useful after that and I cancel the test runs. I also watch ls /tmp as I clicked on a test run and only saw the -result files appear. No IDs files.

@eleanorjboyd
Copy link
Member

@karthiknadig any thoughts on why the temp file creation is not working?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 11, 2024
@karthiknadig
Copy link
Member

karthiknadig commented Nov 11, 2024

It might be permissions issue with this. We might need to add a check that verifies that the temp file was created. The other thing is not really a file, it is a Unix Domain Socket. I would check permissions first.

@paul-voelker
Copy link

For me on macOS 14.6.1 the error looks like this:

Error[vscode-pytest]: unable to read testIds from temp file[Errno 2] No such file or directory: '/var/folders/f5/9qsxm9ds2nd788spvqqq6hf40000gn/T/test-ids-bd662f439a6f58d10bbe.txt'

The directory exists and there are plenty of other vscode related files in there (called something like vscode-git-0b14b03a2b.sock, pyright-98926-9DQScs6SskRz, etc.), so maybe not a permission problem?

@karthiknadig karthiknadig added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2024
Copy link

Hey @eleanorjboyd, this issue might need further attention.

@RamiAwar, you can help us out by closing this issue if the problem no longer exists, or adding more information.

@karthiknadig karthiknadig added needs spike Label for issues that need investigation before they can be worked on. and removed info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels Jan 19, 2025
@eleanorjboyd
Copy link
Member

@RamiAwar what machine type are you on? Do you know if you have any permissions added by an administration?

@RamiAwar
Copy link
Author

RamiAwar commented Feb 4, 2025

I'm on a work macbook.

Even on that machine, I don't have a problem with regular VSCode running tests, only the devcontainer-ized version!

@karthiknadig
Copy link
Member

@eleanorjboyd May be we can check for this on TS side? I think we can do an access check on the location where we create the file, and log if that is failing. Or attempt an alternate location.

@eleanorjboyd
Copy link
Member

added a check on the ts side for the temp file. @RamiAwar if you are able to try the python extension pre-release it should be fixed but let me know if not! Thanks

@RamiAwar
Copy link
Author

RamiAwar commented Feb 14, 2025

Hmm not sure what I'm doing wrong but I still get the same issue. I installed pre-release (2025.1.2025021401) on my devcontainer, and then opened up test explorer and tried launching some tests.


Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=/code/notify', '/code/notify/triggers/email/tests/test_views.py::test_trigger_email_preview', ...]


re-exec with libfaketime dependencies
Error[vscode-pytest]: unable to read testIds from temp file[Errno 2] No such file or directory: '/tmp/test-ids-aefc6aebb8cd5963192d.txt'
============================= test session starts ==============================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
django: version: 5.1.6, settings: sendcloud.settings.usestubserver (from option)
rootdir: /code/scp/python/sendcloud/frontend/xhr/notify
configfile: ../../../../../pyproject.toml
plugins: Faker-33.3.1, test-groups-1.0.3, metadata-3.1.1, cov-6.0.0, requests-mock-1.12.1, django-4.10.0, ddtrace-2.20.1, xdist-3.6.1, bdd-8.1.0, html-4.1.1
collected 619 items

Then it proceeds to just run all the tests instead of the ones I asked for.

Don't think this fixed it sorry :( @eleanorjboyd

I included the specific command details being run, maybe you can spot something that's off there?

@eleanorjboyd
Copy link
Member

what is your log level at? Can you make sure it is on trace (you can do this by running "developer: set log level" in the command palette). I have these two logs which you should be able to find that would give us more info:

this you should see regardless:
traceLog('Attempting to use temp directory for test ids file, file name:', tempName);

this you should see if an error on accessing is returned:
traceError('Error accessing temp directory:', error, ' Attempt to use extension root dir instead');

here's the whole chunk of code: https://github.com/soceanainn/vscode-python/blob/233569307ef9f232aa06707afae799f36a640a62/src/client/testing/testController/common/utils.ts#L52-L66

@RamiAwar
Copy link
Author

Okay I see them now, I was looking at the Test Explorer output not the Python extension output.

2025-02-16 08:20:51.188 [debug] Found cached env for /usr/local/bin/python
2025-02-16 08:20:51.202 [debug] Starting Test Result named pipe
2025-02-16 08:20:51.207 [debug] Test Results named pipe /tmp/python-test-results-b34427d2263e761006ac connected
2025-02-16 08:20:51.210 [debug] could not find a pixi interpreter for the interpreter at /usr/local/bin/python
2025-02-16 08:20:51.262 [debug] Activation Commands received undefined for shell bash, resource /code/scp and interpreter /usr/local/bin/python
2025-02-16 08:20:51.264 [debug] Executable path for pytest execution: /usr/local/bin/python.
2025-02-16 08:20:51.264 [info] arg: --rootdir already exists in args, not adding.
2025-02-16 08:20:51.264 [info] Attempting to use temp directory for test ids file, file name: test-ids-3b41308749f2e7229317.txt
2025-02-16 08:20:51.271 [info] All environment variables set for pytest execution, PYTHONPATH: "/root/.vscode-server/extensions/ms-python.python-2025.1.2025021102-linux-arm64/python_files:/code/scp/python:/code/scp/python"
2025-02-16 08:20:51.271 [info] Running pytest with arguments: /root/.vscode-server/extensions/ms-python.python-2025.1.2025021102-linux-arm64/python_files/vscode_pytest/run_pytest_script.py --rootdir=/code/<redacted> for workspace /code/scp 

2025-02-16 08:20:51.271 [info] > /usr/local/bin/python ~/.vscode-server/extensions/ms-python.python-2025.1.2025021102-linux-arm64/python_files/vscode_pytest/run_pytest_script.py --rootdir=./<redacted>
2025-02-16 08:20:51.271 [info] cwd: ./<redacted>
2025-02-16 08:20:58.978 [info] Test Result named pipe /tmp/python-test-results-b34427d2263e761006ac  cancelled
2025-02-16 08:20:58.978 [debug] Test Results named pipe /tmp/python-test-results-b34427d2263e761006ac disposed
2025-02-16 08:20:58.978 [info] Test run cancelled, resolving 'TillServerClose' deferred for /code/scp.
2025-02-16 08:20:58.978 [info] Test run cancelled, killing pytest subprocess for workspace /code/scp
2025-02-16 08:20:58.978 [debug] Finished running tests, ending runInstance.
2025-02-16 08:21:01.697 [debug] Found cached env for /usr/local/bin/python

The last few are because I cancelled the run as all the tests were being run, not just the ones I selected.

@RamiAwar
Copy link
Author

@eleanorjboyd let me know how I can debug this further - I'd reaaally like to have this functionality working in my devcontainer, and I'm kind of restricted to using a devcontainer for the time being sadly.

I tried digging some more today but didn't really find anything sadly.

$ ls -ld /tmp
drwxrwxrwt 1 root root 4096 Feb 20 12:20 /tmp

I tried adding an alternative 'basetemp' argument to pytest but it wasn't picking it up sadly, still using /tmp for the IDs in the vscode_pytest plugin I think:

Running pytest with args: ['-p', 'vscode_pytest', '--basetemp=/code/tmp', '--rootdir=/code/scp/python/...', '/code/scp/python/...test_views.py::test_get_list_triggers_emails']

re-exec with libfaketime dependencies
Error[vscode-pytest]: unable to read testIds from temp file[Errno 2] No such file or directory: '/tmp/test-ids-3ac1c00f80a2fe21b568.txt'

Wondering if I can specify a different temp directory for this plugin, then maybe permissions issues can be ruled out?

@eleanorjboyd eleanorjboyd reopened this Feb 20, 2025
@eleanorjboyd
Copy link
Member

it is interesting the check for the temp directory is not catching it- it seems then that the extension (in ts) can access it but that the python subprocess running the tests cannot. @karthiknadig any ideas?

I could allow a special argument in the pytest args like --VSCODE_TEMP_COMMS_PATH which I would use instead and that could be added without the need for a vscode setting which would be nice / simpler.

@karthiknadig
Copy link
Member

@eleanorjboyd It looks like we use default tmp dir. I think we should be using XDG_RUNTIME_DIR for Mac. See the implementation for generating named pipes, for path generation on non-windows. We can try using that, and in addition we can also add access check so we can report errors.

@RamiAwar
Copy link
Author

RamiAwar commented Feb 21, 2025

Note that I'm running this on a linux container on my mac, not directly on my mac.

I don't think the problem is mac specific. On my mac this works fine, it's just inside the devcontainer vscode instance that this fails!
@karthiknadig

@eleanorjboyd eleanorjboyd removed this from the February 2025 milestone Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug needs spike Label for issues that need investigation before they can be worked on.
Projects
None yet
4 participants