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

Spawn for running test discovery is not following symlinks properly. #9347

Closed
JacekPliszka opened this issue Dec 31, 2019 · 33 comments
Closed
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@JacekPliszka
Copy link

JacekPliszka commented Dec 31, 2019

Environment data

  • VS Code version: 1.41.1 26076a4de974ead31f97692a0d32f90d735645c0
  • Extension version (available under the Extensions sidebar): 2019.11.50794
  • OS and version: Fedora Linux 31
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: Python 3.7.5, pytest-4.6.7, py-1.8.0, pluggy-0.12.0
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): "python.jediEnabled": true

Expected behaviour

tests are detected

Actual behaviour

tests are not detected, error is issues, running the adapter returns:

$ python /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jp/py/vscode -s --cache-clear
[{"rootid": ".", "root": "/home/jp/py/vscode", "parents": [{"id": "./test_simple.py", "kind": "file", "name": "test_simple.py", "parentid": ".", "relpath": "./test_simple.py"}], "tests": [{"id": "./test_simple.py::test_simple", "name": "test_simple", "source": "./test_simple.py:1", "markers": [], "parentid": "./test_simple.py"}]}]

Steps to reproduce:

  1. Create minimal repo with:
$ cat test_simple.py 
def test_simple():
    assert 2 + 2 == 4
$ cat .vscode/settings.json 
{
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true
}
  1. run:

code .

  1. open test_simple.py and click Discover Tests

Logs

python /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /home/jp/py/vscode -s --cache-clear
Test Discovery failed: 
TypeError: Cannot read property 'uri' of undefined

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: Cached data exists ActivatedEnvironmentVariables, /home/jp/py/vscode
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: getActivatedEnvironmentVariables, Class name = b, completed in 1ms, Arg 1: <Uri:/home/jp/py/vscode>, Arg 2: undefined, Arg 3: false
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: Cached data exists getEnvironmentVariables, /home/jp/py/vscode
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: > /usr/bin/python ~/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/py/vscode -s --cache-clear
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: cwd: ~/python-etl/base-code
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: > /usr/bin/python ~/.vscode/extensions/ms-python.python-2019.11.50794/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/py/vscode -s --cache-clear
console.ts:137 [Extension Host] Info Python Extension: 2019-12-31 20:05:49: cwd: ~/python-etl/base-code
notificationsAlerts.ts:40 Test discovery error, please check the configuration settings for the tests.
onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
fire @ event.ts:581
addNotification @ notifications.ts:171
notify @ notificationService.ts:101
(anonymous) @ mainThreadMessageService.ts:83
_showMessage @ mainThreadMessageService.ts:44
$showMessage @ mainThreadMessageService.ts:38
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
console.ts:137 [Extension Host] Error Python Extension: 2019-12-31 20:05:50: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined	at /home/jp/.vscode/extensions/ms-python.python-2019.11.50794/out/client/extension.js:1:475432]
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
@JacekPliszka JacekPliszka added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Dec 31, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Dec 31, 2019
@ericsnowcurrently
Copy link
Member

Thanks for letting us know about this, @JacekPliszka. We'll take a look as soon as we can.

@toddljones
Copy link

+1. I am having the same issue. Although, intermittently, I am able to reload window then the test discovery starts working. But, even then, when I run the tests it fails out because it can't find the test file. For some reason the relative path test is not included and the test execution fails. See issue #9349

@ericsnowcurrently
Copy link
Member

@JacekPliszka, I wasn't able to reproduce the problem. Using the simple example you provided, the extension was able to discover the test without problem. Is it happening every time for you?

Since running the command manually worked for you, we know that the problem isn't related to the output of the command. There is something wrong in the extension (at least your install, if not the extension itself). However, it will be hard to determine the cause until we can reliably reproduce the problem.

FWIW, the displayDiscoverStatus reference in the log output you included helps narrow down where the error is originating.

@ericsnowcurrently ericsnowcurrently added area-testing info-needed Issue requires more information from poster labels Jan 8, 2020
@JacekPliszka
Copy link
Author

JacekPliszka commented Jan 8, 2020

Yes. Happens every time. With any project. This is my first install and the first time I use vscode for anything.

I do not know Javascript so I do not know how to debug it.

What would be useful is better error message/issue detection. Something is undefined but should not be but what and why - I've no idea.

@ericsnowcurrently
Copy link
Member

Yeah, I agree that the error message is unhelpful. Sorry about that. Would you mind trying the latest version of the extension (released just yesterday)?

@JacekPliszka
Copy link
Author

updated - no change.

I believe I have something missing in setup and the extension is not detecting it and not telling me and I do not know what to do.

@ericsnowcurrently
Copy link
Member

Understood. I'll try to narrow down the possible problematic code (based on displayDiscoverStatus) as soon as I can.

@ericsnowcurrently ericsnowcurrently removed the info-needed Issue requires more information from poster label Jan 8, 2020
@ericsnowcurrently
Copy link
Member

@JacekPliszka, during discovery did a message like the following pop up?

No tests discovered, please check the configuration settings for the tests.

@JacekPliszka
Copy link
Author

JacekPliszka commented Jan 8, 2020

No

Test discovery error, please check the configuration settings for the tests.

It is at the top of the log I've pasted

@ericsnowcurrently
Copy link
Member

What is in your settings.json file?

@JacekPliszka
Copy link
Author

Same what I've pasted under steps to reproduce

$ cat .vscode/settings.json 
{
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true
}```

@ericsnowcurrently
Copy link
Member

Do you have a workspace file?

Also, what do you see in the status bar when you discover tests? It should show "Discovering Tests" and then change depending on the outcome. (On success it says "Run Tests".)

@JacekPliszka
Copy link
Author

JacekPliszka commented Jan 8, 2020

This is all I have

$find
.
./test_simple.py
./__pycache__
./__pycache__/test_simple.cpython-37-PYTEST.pyc
./1577819190660.log
./.pytest_cache
./.pytest_cache/v
./.pytest_cache/v/cache
./.pytest_cache/v/cache/stepwise
./.pytest_cache/v/cache/nodeids
./.pytest_cache/v/cache/lastfailed
./.vscode
./.vscode/settings.json

In status bar I have

Discovering Tests

and then

Test discovery failed

@ericsnowcurrently
Copy link
Member

Thanks. That helps.

@ericsnowcurrently
Copy link
Member

Given that info, we know that the problem is somewhere under the call to the pytest TestManager's discoverTests() method. There's a lot going on there, so narrowing that down will be somewhat difficult without a consistent reproducer. (FWIW, even though the error mentions displayDiscoverStatus, the problem happens elsewhere and only surfaces in displayDiscoverStatus() due to a promise used there.)

@JacekPliszka, in the Developer Tools console output you included above, we found a relevant error. However, it should have also included a stack trace pointing to the code where the error originated. Were there any such lines there that got missed when you copied the text into this issue? It may help to change the log levels filter at the top of the Developer Tools console (it may say "Default levels"). Change it so only "Errors" is checked.

@ericsnowcurrently ericsnowcurrently added the info-needed Issue requires more information from poster label Jan 9, 2020
@JacekPliszka
Copy link
Author

OK, now I am getting python error too. I do not know why it is calling tests in different directory.

But regardless of it - vscode should be able to handle it gracefully with some meaningful error message.

Errors was checked - I unchecked the other. The result are 3 entries

console.ts:137 [Extension Host] Error Python Extension: 2020-01-10 12:05:56: Failed to parse 
.... <HERE is my python error> ...
Exception: pytest discovery failed (exit code 2)	at ChildProcess.<anonymous> (~/.vscode/extensions/ms-python.python-2020.1.57204/out/client/extension.js:1:438684)	at Object.onceWrapper (events.js:288:20)	at ChildProcess.emit (events.js:200:13)	at maybeClose (internal/child_process.js:1021:16)	at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)]
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
notificationsAlerts.ts:40 Test discovery error, please check the configuration settings for the tests.
onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
fire @ event.ts:581
addNotification @ notifications.ts:171
notify @ notificationService.ts:101
(anonymous) @ mainThreadMessageService.ts:83
_showMessage @ mainThreadMessageService.ts:44
$showMessage @ mainThreadMessageService.ts:38
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
console.ts:137 [Extension Host] Error Python Extension: 2020-01-10 12:05:56: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined	at ~/.vscode/extensions/ms-python.python-2020.1.57204/out/client/extension.js:1:522555]
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166

@JacekPliszka
Copy link
Author

JacekPliszka commented Jan 10, 2020

OK, looks like there was config in ~/.config/Code/ - testing working directory should be per project/workspace, not global.

After fixing this I got

console.ts:137 [Extension Host] Error Python Extension: 2020-01-10 12:24:18: Failed to parse discovered Test [Error: spawn /usr/bin/python ENOENT	at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)	at onErrorNT (internal/child_process.js:456:16)	at processTicksAndRejections (internal/process/task_queues.js:84:9)] {  errno: 'ENOENT',  code: 'ENOENT',  syscall: 'spawn /usr/bin/python',  path: '/usr/bin/python',  spawnargs: [    '~/.vscode/extensions/ms-python.python-2020.1.57204/pythonFiles/testing_tools/run_adapter.py',    'discover',    'pytest',    '--',    '--rootdir',    '~/py/vscode',    '-s',    '--cache-clear'  ]}
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
notificationsAlerts.ts:40 Test discovery error, please check the configuration settings for the tests.
onDidNotificationChange @ notificationsAlerts.ts:40
(anonymous) @ notificationsAlerts.ts:26
fire @ event.ts:581
addNotification @ notifications.ts:171
notify @ notificationService.ts:101
(anonymous) @ mainThreadMessageService.ts:83
_showMessage @ mainThreadMessageService.ts:44
$showMessage @ mainThreadMessageService.ts:38
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
console.ts:137 [Extension Host] Error Python Extension: 2020-01-10 12:24:18: Python Extension: displayDiscoverStatus [TypeError: Cannot read property 'uri' of undefined	at ~/.vscode/extensions/ms-python.python-2020.1.57204/out/client/extension.js:1:522555]
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:398
_invokeHandler @ rpcProtocol.ts:383
_receiveRequest @ rpcProtocol.ts:299
_receiveOneMessage @ rpcProtocol.ts:226
(anonymous) @ rpcProtocol.ts:101
fire @ event.ts:581
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:581
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:200
addChunk @ _stream_readable.js:294
readableAddChunk @ _stream_readable.js:275
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166

command line run:

$ /usr/bin/python ~/.vscode/extensions/ms-python.python-2020.1.57204/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir ~/py/vscode -s --cache-clear
[{"rootid": ".", "root": "~/py/vscode", "parents": [{"id": "./test_simple.py", "kind": "file", "name": "test_simple.py", "parentid": ".", "relpath": "./test_simple.py"}], "tests": [{"id": "./test_simple.py::test_simple", "name": "test_simple", "source": "./test_simple.py:1", "markers": [], "parentid": "./test_simple.py"}]}]

@ericsnowcurrently
Copy link
Member

Yeah, I agree that the "TypeError: Cannot read property 'uri' of undefined" error is basically useless (both for you and for us). We will work on fixing that (see #9521).

As to the problem, VS Code (actually, Node JS) is saying that your operating system couldn't find /usr/bin/python. Given that you can run that manually without trouble, something fishy is going on. Also, presumably the extension is otherwise working just fine and you can run Python code and debug it without trouble. Is that true?

Please provide the contents of the "Python" output panel. Also, are you using any remote extensions?

@ericsnowcurrently ericsnowcurrently added the info-needed Issue requires more information from poster label Jan 14, 2020
@eleanorjboyd
Copy link
Member

dup of #9347, hopefully, it can be addressed soon now that we are rolling out the rewrite.

@github-actions github-actions bot removed the needs PR Ready to be worked on label Jul 14, 2023
@eleanorjboyd eleanorjboyd reopened this Aug 4, 2023
@eleanorjboyd eleanorjboyd added the needs PR Ready to be worked on label Aug 4, 2023
@eleanorjboyd eleanorjboyd self-assigned this Aug 4, 2023
@eleanorjboyd eleanorjboyd added this to the August 2023 milestone Aug 4, 2023
@eleanorjboyd
Copy link
Member

eleanorjboyd commented Aug 16, 2023

Steps to reproduce:
#9347 (comment)

tried these steps and was able to find and run tests with pytest.

Are people still seeing issues currently on insiders? Could someone provide a minimal repro or steps to create one if so?

@eleanorjboyd eleanorjboyd added the info-needed Issue requires more information from poster label Aug 16, 2023
@eleanorjboyd
Copy link
Member

repost from #21373, trying to consolidate discussion of testing with symlinks there.

my msg:
Hi! Looking to fix this but having trouble getting a minimal repro that produces the error. I have tried to replicate it via symlinks on a single disk (but it works) so I think it might only occur when you have symlinks across two different disks. Is that how everyone's setup is?

@eleanorjboyd
Copy link
Member

Closing this issue since it has been a month and I haven't gotten any response to my above post regarding a minimal repro. Please comment if you are still seeing this and have a repo I can debug with and Ill reopen the issue. Thanks!

@eleanorjboyd eleanorjboyd closed this as not planned Won't fix, can't repro, duplicate, stale Sep 25, 2023
@github-actions github-actions bot removed the needs PR Ready to be worked on label Sep 25, 2023
@karthiknadig karthiknadig removed this from the September 2023 milestone Sep 26, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2023
@eleanorjboyd
Copy link
Member

Hello! I was able to figure out a repo and a solution. I have put together a detailed problem report and proposed solution for symlinks. Please check it out here and contribute any thoughts you may have: #22658

@eleanorjboyd eleanorjboyd reopened this Dec 18, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Dec 18, 2023
@eleanorjboyd eleanorjboyd removed info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels Jan 25, 2024
@eleanorjboyd
Copy link
Member

Hello! This bug should be fixed and on vscode insiders! The release to vscode stable will be out by the end of the week. Please let me know if you try it on insiders or stable when it comes out and still doesn't work and I can investigate your specific issue further.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests