kondratyev-nv / vscode-python-test-adapter

Python Test Adapter for the VS Code Test Explorer
https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter
MIT License
117 stars 27 forks source link

[pytest] test states not displayed #291

Open mayrholu opened 1 year ago

mayrholu commented 1 year ago

When using pytest the icons in the test explorer remain gray (no matter if tests fail or pass).

The output shows the following (I had to mask actual paths and names):

2023-01-25T15:28:40.343Z INFO pytest at 'xyz': Reading configuration for workspace xyz
2023-01-25T15:28:40.344Z  DBG pytest at 'xyz': usingNewInterpreterStorage feature flag is 'true'
2023-01-25T15:28:40.344Z INFO pytest at 'xyz': Using auto-detected pythonPath /<path>/python
2023-01-25T15:28:40.345Z INFO pytest at 'xyz': Running tests using python path '/<path>/python' in /<path>/xyz
2023-01-25T15:28:40.346Z INFO pytest at 'xyz': Loading environment variables file /<path>/xyz/.env
2023-01-25T15:28:40.352Z INFO pytest at 'xyz': Running pytest with arguments: --rootdir=/<path>/xyz, --junitxml=/<tmp-path>/tmp-7245-mawg3A03U6qr, --override-ini, junit_family=xunit1, /<path>/xyz/tests/test_xyz.py::test_xyz1
2023-01-25T15:28:40.353Z INFO pytest at 'xyz': Running pytest as a Python module
2023-01-25T15:28:41.960Z INFO pytest at 'xyz': Test execution completed

When I click on "Debug this test" the following output is shown in debug terminal:

============================= test session starts ==============================
platform linux -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0
rootdir: /<path>/xyz/tests
collected 1 item
==DISCOVERED TESTS BEGIN==
{"tests": [{"id": "test_xyz.py::test_xyz1", "line": 251}], "errors": []}
==DISCOVERED TESTS END==

../../../../../../../<path>/xyz/tests/test_xyz.py . [100%]

============================== 1 passed in 1.41s ===============================

Python version is 3.11.0 (also reproducable with 3.10.4 and 3.8.3). Python Test Explorer version is 0.7.1 Running VSCode 1.74.0 on Linux (SuSE SLE15)

No problems when switching to unittest, however most of our test suite is designed for pytest. Any help would be appreciated!

bdovaz commented 1 year ago

Same problem here

MichalMazurek commented 1 year ago

On my side, some are fine; some do not show the state after the run.

kondratyev-nv commented 1 year ago

I was not able to easily reproduce this. Any code/repo example to share?

@mayrholu Does <path>s that you've hidden look good to you? Does your working directory set to the path to the project?

bdovaz commented 1 year ago

@kondratyev-nv it happens to me directly with: https://github.com/oxsecurity/megalinter

kondratyev-nv commented 1 year ago

@bdovaz Thanks! I see most tests do not get the right test state in this repo. This is due to tests being defined in the parent class (LinterTestRoot) and the extension not being able to resolve the right test ID. Other tests (e.g., config_test) seems to be working fine for me.

@MichalMazurek @mayrholu Are you using parent classes for tests as well?

mayrholu commented 1 year ago

Sorry for the late reply!

For me it happens even in the super simple case here:

Project folder with only one file: ./tests/test_pytest.py

Content:

def test_pytest_1():
    assert True

def test_pytest_2():
    assert False
rcartmil commented 1 year ago

@kondratyev-nv I'm experiencing this problem too. If I run my pytest unit tests in Test Explorer in VS Code, they "flash blue", then the icons are grayed out again. If I then look at Output->Python Test Adaptor Log, then the Running pytest with arguments: line, copy the arguments, remove the commas, then run the result in the Bash terminal, the tests run successfully.

Note that both successful and failed test results are not displayed; everything is just "gray" after the tests are run.

mayrholu commented 1 year ago

@kondratyev-nv is there any additional output/info I can provide you with or test something to get this issue resolved?

shaulimaya commented 1 year ago

I have the same issue, any suggesting?

Zetaeta commented 1 year ago

I had the same problem, caused by the matchParentPath function failing on the unusual path ../../../../../<path>/test/test_treeview_tests.py produced by pytest. It seemed to be caused by the combination of the absolute rootpath passed to pytest and the fact that my workspace path contained a symlink. Opening the workspace by its true path fixed the problem for me.

rcartmil commented 1 year ago

@Zetaeta Do you mean you opened the workspace in VS Code without the symlink? We do have a symlink in our path.

I'll try opening the workspace tomorrow via the non-symlink path, and report back.

Zetaeta commented 1 year ago

@rcartmil Yes, I opened the workspace by navigating to the original non-symlinked path and everything started working (including the built in python test explorer, which not working was what caused me to install this extension in the first place).

rcartmil commented 1 year ago

@Zetaeta Wow, you are amazing! This solved my problem too! You've certainly made my day!

rcartmil commented 1 year ago

And just to be clear, both the original "Test Explorer" and this Python Test Adapter's "Test Explorer" are working now, same as you.

mayrholu commented 1 year ago

Hi there, while the workaround is great, it’s not a longtime solution for the problem. Is there any plans on fixing this? Or any hints on where to look for the problem so I can give it a try?