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

Unable to discover using pytest #20750

Closed
weimin opened this issue Feb 24, 2023 Discussed in #20744 · 20 comments
Closed

Unable to discover using pytest #20750

weimin opened this issue Feb 24, 2023 Discussed in #20744 · 20 comments
Assignees
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@weimin
Copy link

weimin commented Feb 24, 2023

Discussed in #20744

Originally posted by weimin February 23, 2023
I got this error in vscode, I checked this in this repo and also on stackoverflow but could not find the fix:

Python interpreter path: /workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python
> /workplace/chaweimi/mc_experiments/.bemol/CPPAutoMLQueryAcquisition-1.0/Python/farm/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
Starting Pylance language server.
[ERROR 2023-1-24 0:45:37.249]: Active interpreter type is detected as Unknown {"id":"/workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python","sysPrefix":"/local/home/chaweimi/brazil-pkg-cache/packages/CPython37Runtime/CPython37Runtime-release.498104.0/AL2_x86_64/DEV.STD.PTHREAD/build/python3.7","envType":"Unknown","envName":"","envPath":"","path":"/workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python","architecture":3,"sysVersion":"3.7.16 (default, Jan 18 2023, 23:05:52) \n[GCC 7.5.0]","version":{"raw":"3.7.16","major":3,"minor":7,"patch":16,"build":[],"prerelease":["final","0"]},"displayName":"Python 3.7.16 64-bit","detailedDisplayName":"Python 3.7.16 64-bit"}
> conda info --json
> /usr/share/anaconda/bin/conda info --json
> /bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /bin/python3 /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /usr/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /usr/bin/python3 /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /apollo/env/envImprovement/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /apollo/env/envImprovement/bin/python3 /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /apollo/env/envImprovement/bin/python3.8 /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/get_output_via_markers.py /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/interpreterInfo.py
> /workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /workplace/chaweimi/mc_experiments/src/CPPActiveLearningWeb --cache-clear -s --no-cov
cwd: /workplace/chaweimi/mc_experiments/src/CPPActiveLearningWeb
[ERROR 2023-1-24 0:45:46.400]: Error discovering pytest tests:
 [SyntaxError: 
	at JSON.parse (<anonymous>)
	at s.runTestDiscovery (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:757144)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async Promise.all (index 0)
	at async _.refreshTestData (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:786783)
	at async C.refreshTestDataInternal (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:773814)
	at async /local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:775456
	at async Promise.all (index 0)
	at async C.resolveChildren (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:775363)]
Python interpreter path: /workplace/chaweimi/mc_experiments/.bemol/CPPAutoMLQueryAcquisition-1.0/Python/farm/bin/python
Starting Pylance language server.
Python interpreter path: /workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python

My vscode is Version: 1.74.3 (Universal) and my python extension is v2022.20.2

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 24, 2023
@karrtikr
Copy link

The error just means that the interpreter which is selected: /workplace/chaweimi/mc_experiments/.bemol/CPPAutoMLQueryAcquisition-1.0/Python/farm/bin/python was not auto-discovered by the Python extension, did you manually select it by browsing or entering the full path?

Also, how is that interpreter created?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Feb 24, 2023
@weimin
Copy link
Author

weimin commented Feb 24, 2023

Thanks for your reply, I will check and get back to you!

@weimin

This comment was marked as resolved.

@karrtikr

This comment was marked as resolved.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2023
@weimin

This comment was marked as resolved.

@karrtikr

This comment was marked as resolved.

@karrtikr

This comment was marked as resolved.

@weimin

This comment was marked as resolved.

@karrtikr karrtikr reopened this Feb 27, 2023
@karrtikr
Copy link

I see, try using the full path /local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/testing_tools/run_adapter.py instead. See if you can cd into /local/home/chaweimi.

Reassigning this to testing.

@karrtikr karrtikr changed the title Active interpreter type is detected as Unknown Unable to discover using pytest when active interpreter type is detected as Unknown Feb 27, 2023
@karrtikr karrtikr assigned eleanorjboyd and unassigned karrtikr Feb 27, 2023
@weimin

This comment was marked as resolved.

@karrtikr

This comment was marked as resolved.

@weimin

This comment was marked as resolved.

@karrtikr

This comment was marked as resolved.

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label Feb 28, 2023
@weimin
Copy link
Author

weimin commented Feb 28, 2023

Hi,
I have resolve the Active interpreter type is detected as Unknown error, only the second error is there now:

> /workplace/chaweimi/mc_experiments/.bemol/CPPActiveLearningWeb-1.0/Python/farm/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /workplace/chaweimi/mc_experiments/src/CPPActiveLearningWeb --cache-clear -s --no-cov
cwd: /workplace/chaweimi/mc_experiments/src/CPPActiveLearningWeb
> /workplace/chaweimi/mc_experiments/src/CPPAutoMLQueryAcquisition/../../.bemol/CPPAutoMLQueryAcquisition-1.0/Python/farm/bin/python /local/~/.vscode-server/extensions/ms-python.python-2022.20.2/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /workplace/chaweimi/mc_experiments/src/CPPAutoMLQueryAcquisition --cache-clear -s --no-cov
cwd: /workplace/chaweimi/mc_experiments/src/CPPAutoMLQueryAcquisition
[ERROR 2023-1-28 17:51:58.411]: Error discovering pytest tests:
 [SyntaxError: 
	at JSON.parse (<anonymous>)
	at s.runTestDiscovery (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:757144)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)
	at async Promise.all (index 0)
	at async _.refreshTestData (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:786783)
	at async C.refreshTestDataInternal (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:773814)
	at async /local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:774640
	at async Promise.all (index 0)
	at async C.refreshTestDataInternal (/local/home/chaweimi/.vscode-server/extensions/ms-python.python-2022.20.2/out/client/extension.js:2:774547)
	at async s.$refreshTests (/local/home/chaweimi/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:96:140094)]

@karrtikr karrtikr changed the title Unable to discover using pytest when active interpreter type is detected as Unknown Unable to discover using pytest Feb 28, 2023
@eleanorjboyd
Copy link
Member

What happens when you run this from your integrated terminal? pytest /workplace/chaweimi/mc_experiments/src/CPPAutoMLQueryAcquisition --cache-clear -s --no-cov

@ksamborn
Copy link

Hi @eleanorjboyd -

I experienced a similar if not the same problem. This is also described in the issue #20913, which is exactly the problem i have.

It seems to be related to a importing an object and executing code at import time. (the "Global Object Pattern")

You can reproduce it with these two files:

inc_dec.py:

from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()

def increment(x):
    return x + 1

def decrement(x):
    return x - 1

and the test, test_pytest.py

import pytest
from pyspark.sql import DataFrame

import inc_dec as inc_dec    # The code to test

@pytest.fixture
def dataframe(spark) -> DataFrame:
    df = inc_dec.spark.createDataFrame([
        (1, "AAAA"),
        (2, "BBBB")],
        ["id", "value"])

    return df

def test_spark(dataframe):
    dataframe.collect()

    i = inc_dec.increment(1)

    assert i == 2

you will need to set PYTHONPATH AND PYSPARK_PYTHON in your .env file:

PYTHONPATH=${env:PYTHONPATH};./main/src
PYSPARK_PYTHON=python

Here is the full output I get, including the stack trace:

[ERROR 2023-3-23 15:53:16.347]: Error discovering pytest tests:
 [SyntaxError: [{"rootid": ".", "root": "c:\\Users\\sambornk\\scratch\\vs.code test discovery fails", "parents": [{"id": "./main", "kind": "folder", "name": "main", "parentid": ".", "relpath": ".\\main"}, {"id": "./main/test", "kind": "folder", "name": "test", "parentid": "./main", "relpath": ".\\main\\test"}, {"id": "./main/test/test_pytest.py", "kind": "file", "name": "test_pytest.py", "parentid": "./main/test", "relpath": ".\\main\\test\\test_pytest.py"}], "tests": [{"id": "./main/test/test_pytest.py::test_spark", "name": "test_spark", "source": ".\\main\\test\\test_pytest.py:15", "markers": [], "parentid": "./main/test/test_pytest.py"}]}]
SUCCESS: The process with PID 92032 (child process of PID 80660) has been terminated.
SUCCESS: The process with PID 80660 (child process of PID 92984) has been terminated.
SUCCESS: The process with PID 92984 (child process of PID 87336) has been terminated.

	at JSON.parse (<anonymous>)
	at s.runTestDiscovery (c:\Users\sambornk\.vscode\extensions\ms-python.python-2023.6.1\out\client\extension.js:2:798405)
	at async Promise.all (index 0)
	at async _.refreshTestData (c:\Users\sambornk\.vscode\extensions\ms-python.python-2023.6.1\out\client\extension.js:2:828135)
	at async I.refreshTestDataInternal (c:\Users\sambornk\.vscode\extensions\ms-python.python-2023.6.1\out\client\extension.js:2:815130)]

If I remove the global object import and instead create it as a fixture, it works. In fact, if I edit the files to work around the issue and the tests are discovered, I can then still run and debug the tests - but the discovery error is there anyway.

Thanks and I hope this helps.

Kevin

@eleanorjboyd
Copy link
Member

Hi! This should be fixed by our rewrite of the testing logic which is close to completion, you can follow along for updates here: #17242

@ksamborn
Copy link

Thanks! Looking forward to it

@eleanorjboyd
Copy link
Member

Hello! We have just finished our testing rewrite and are beginning the roll out to users. If you are able, it would be very helpful to know if your issue still exists on the rewrite! To try it yourself, you need to be on the most recent release of the Python extension and add this setting to your users settings.json "python.experiments.optInto": ["pythonTestAdapter"].

You can confirm you have the rewrite enabled by setting "python.analysis.logLevel": "Trace", in your user settings then check for Experiment 'pythonTestAdapter' is active in your python logs.

Let me know if the rewrite fixes your issue. Thanks!

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Jul 10, 2023
@github-actions
Copy link

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants