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

Can't run test using Test Function, Test File, Test Module, only Run All Tests works #7747

Closed
lightme16 opened this issue Oct 2, 2019 · 3 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@lightme16
Copy link

lightme16 commented Oct 2, 2019

Environment data

  • VS Code version:
    Version: 1.38.1
    Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
    Date: 2019-09-11T13:31:32.854Z
    Electron: 4.2.10
    Chrome: 69.0.3497.128
    Node.js: 10.11.0
    V8: 6.9.427.31-electron.0
    OS: Darwin x64 18.7.0
  • Extension version (available under the Extensions sidebar): 2019.9.34911
  • OS and version: MacOS Mojave 10.14.6
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.3
    -Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv

Expected behaviour

I can press "Run Test" above the pytest function and test will be executed

Actual behaviour

After pressing the "Run Test" I can see error notifications:

  • There was an error in running the tests.
  • cannot open file:///<FILE_PATH_HERE>. Detail: Unable to read file (Error: File not found (<FILE_PATH_HERE>))

image

FILE_PATH_HERE indeed is not exists, but I can see that path is crafter incorrectly.
Real file path(some names changed) - /Users/username/src/WORKSPACE/SUBDIR/tests/handlers/dir/test_foo.py

FILE_PATH_HERE - /Users/username/src/WORKSPACE/tests/handlers/dir/test_foo.py
So, SUBDIR is lost and due to that path is invlalid.

Other notes

Want to note that I am using a python project with 3 subprojects(SUBDIRs) inside, each of them has it's on Pipfile. I set up vscode python interpreter to be python from one of these subprojects virtualenvs. This interpreter has all other subprojects installed as packages, so it can use them(import code from them).

In the Output -> "Python" I can see:

 ~/.local/share/virtualenvs/foo-DjZHfOUC/bin/python -m pytest --junitxml=/var/folders/62/3bp7qt1n6_d_2k2zzsfkgxbm0000gn/T/tmp-48471eUKjpLhcMaX4.xml ./tests/handlers/dir/test_foo.py::test_my_funciton_to_test
cwd: ~/src/WORKSPACE/

So, I can see that the problem is caused because for some reasons vscode-python is choosing the wrong relative path, when running function test. So, it is basically, building relative path not from WORKSPACE, but from WORKSPACE/SUBDIR/.

I can see this problem when I am running test for single function and for whole module too.

But, I can run all the test using "Run All Tests" button. So, the only option to execute tests it is only run all of them.

Also, I can say that in the previous vscode-python build (maybe month ago) that feature with running single function test was working, so it seems to be broken recently.

@lightme16 lightme16 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Oct 2, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Oct 3, 2019
@karrtikr
Copy link

karrtikr commented Oct 3, 2019

Please paste your settings.json, leave credentials if you have to.
Your issue could be a dup of #6548, where if you've a pytest.ini file, paths are incorrectly calculated. Please let us know about any configuration files you're using.

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Oct 3, 2019
@lightme16
Copy link
Author

lightme16 commented Oct 4, 2019

settings.json:

    "python.jediEnabled": false,
    "[python]": {},
    "gitlens.views.repositories.location": "gitlens",
    "gitlens.views.fileHistory.location": "gitlens",
    "gitlens.views.lineHistory.location": "gitlens",
    "gitlens.views.compare.location": "gitlens",
    "gitlens.views.search.location": "gitlens",
    "diffEditor.renderSideBySide": false,
    "python.formatting.provider": "black",
    "window.zoomLevel": 0,
    "editor.minimap.enabled": false,
    "git.autofetch": true,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "clipboard-manager.onlyWindowFocused": false,
    "files.autoSave": "afterDelay",
    "search.exclude": {
        "**/.tox/**": true,
        "**/mypy_cache": true
    },
    "python.linting.mypyEnabled": true,
    "python.linting.mypyArgs": [
        "--ignore-missing-imports",
        "--strict-optional",
        "--check-untyped-defs",
    ],
    "git.countBadge": "tracked",
    "gitlens.codeLens.authors.enabled": false,
    "gitlens.blame.toggleMode": "window",
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "editor.multiCursorModifier": "ctrlCmd",
    "gitlens.hovers.currentLine.over": "line",
    "python.insidersChannel": "off"
}

Yes, it seems that my problem is related to the #6548.
I have both setup.py and setup.cfg in the WORKSPACE/SUBDIR/.
And from the pytest docs I can read:

Look for pytest.ini, tox.ini and setup.cfg files in the ancestor directory and upwards. If one is matched, it becomes the ini-file and its directory becomes the rootdir.

It is interesting that after removing both setup.py and setup.cfg the issue disappears!
So, it seems that pytest is confused with these filed in the WORKSPACE/SUBDIR/

But I am wondering , why it was working in the previous version of vscode-python?

@karrtikr
Copy link

karrtikr commented Oct 4, 2019

Earlier we were calling pytest to do the discovery and then scraping the output to get the results. But pytest changed the output format unexpectedly due which parsing the output in the extension failed.

So we now have our pytest adapter code in the extension for the discovery, so that we don't have to be dependent on the pytest output. But it led to issues like this, so it still needs some work.

Anyways, closing this issue as dup of #6548

@karrtikr karrtikr closed this as completed Oct 4, 2019
@ghost ghost removed the triage label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants