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

[pytest] test states not displayed #291

Open
mayrholu opened this issue Jan 25, 2023 · 15 comments
Open

[pytest] test states not displayed #291

mayrholu opened this issue Jan 25, 2023 · 15 comments

Comments

@mayrholu
Copy link

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
Copy link

bdovaz commented Jan 25, 2023

Same problem here

@MichalMazurek
Copy link

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

@kondratyev-nv
Copy link
Owner

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
Copy link

bdovaz commented Feb 12, 2023

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

@kondratyev-nv
Copy link
Owner

@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
Copy link
Author

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
Copy link

@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
Copy link
Author

mayrholu commented Mar 3, 2023

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

@shaulimaya
Copy link

I have the same issue, any suggesting?

@Zetaeta
Copy link

Zetaeta commented Apr 3, 2023

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
Copy link

rcartmil commented Apr 3, 2023

@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
Copy link

Zetaeta commented Apr 4, 2023

@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
Copy link

rcartmil commented Apr 4, 2023

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

@rcartmil
Copy link

rcartmil commented Apr 4, 2023

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
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants