Skip to content

Don't add cwd argument when running all tests - #17978

Merged
Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
bhrutledge:17546-run-all-cwd
Nov 16, 2021
Merged

Don't add cwd argument when running all tests#17978
Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
bhrutledge:17546-run-all-cwd

Conversation

@bhrutledge

Copy link
Copy Markdown

Follow-up to #17622 and #17898, attn: Karthik Nadig (@karthiknadig).

I tested this using my example workspace with "python.testing.cwd" set to a sub-directory, and testpaths in pytest.ini set to a sub-directory of that.

Before this change, running all tests yields:

Running tests (pytest): /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir
Running test with arguments: --rootdir /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir --override-ini junit_family=xunit1 --junit-xml=/var/folders/bw/ttgk1hcs0k989q2yzmxkzn8c0000gp/T/tmp-69875H3gF3f2niW84.xml /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir
Current working directory: /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir
Workspace directory: /Users/bhrutledge/Dev/vscode-pytest-workspace
Run completed, parsing output
Test result not found for: ./package/test_module.py::test_function

This is because the cwd is appended as an argument, which causes pytest to ignore testpaths, which causes it to collect tests that it shouldn't, causing a collection error.

With this change, running all tests yields:

Running tests (pytest): /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir
Running test with arguments: --rootdir /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir --override-ini junit_family=xunit1 --junit-xml=/var/folders/bw/ttgk1hcs0k989q2yzmxkzn8c0000gp/T/tmp-71331owgO7UMfr1MG.xml
Current working directory: /Users/bhrutledge/Dev/vscode-pytest-workspace/repo/rootdir
Workspace directory: /Users/bhrutledge/Dev/vscode-pytest-workspace
Run completed, parsing output
./package/test_module.py::test_function Passed

Note that cwd is no longer an argument.

It looks cwd defaults to workspaceFolder.fsPath, so this seems like a safe change.

@karthiknadig Karthik Nadig (karthiknadig) added the skip tests Updates to tests unnecessary label Nov 15, 2021
@karthiknadig
Karthik Nadig (karthiknadig) merged commit f18ee60 into microsoft:main Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip tests Updates to tests unnecessary

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants