question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python.testing.cwd ignored when discovering or running tests using unittest

See original GitHub issue

The issues is similar to https://github.com/microsoft/vscode-python/issues/8678 , but is about unittest, not pytest

Environment data

  • VS Code version: 1.44.0
  • Extension version: 2020.4.74986
  • OS and version: Windows 10 Pro 1903
  • Python version: python 3.7.4 x64
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): True
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

Set python.testing.cwd to correct directory in Workspace settings. Try discovering tests. The test discovery uses the provided cwd.

Actual behaviour

The test discovery ignores the provided cwd.

Output for Python in the Output panel:

Here is what I see during test discovery: (My python.testing.cwd is set to “sdk/python” or “<workspace_root>/sdk/python”).

> .../python ...\.vscode\extensions\ms-python.python-2020.4.74986\pythonFiles\pyvsc-run-isolated.py -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover(".", pattern="*test*.py")
print("start") #Don't remove this line
for suite in suites._tests:
    for cls in suite._tests:
        try:
            for m in cls._tests:
                print(m.id())
        except:
            pass"
cwd: <workspace_root>

See how the bottom line prints a different value of cwd.

P.S. I’m seeing the above log twice every time I try discovering the tests…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
karthiknadigcommented, May 1, 2020

@yandemontreal created an issue on the debugger on your behalf. Please track it there.

0reactions
karthiknadigcommented, May 1, 2020

Closing this, since the original issue with unittest should be addressed in the latest release. @Ark-kun Please let me know if this is not addressed by 2020.4.76186

Read more comments on GitHub >

github_iconTop Results From Across the Web

python.testing.cwd ignored when discovering or running tests
It looks like something is wrong with the file paths. ... is called my current working directory is set to python.testing.cwd and that...
Read more >
vscode-python runs pytest in wrong directory such that relative ...
In the 'Settings' pane, search for 'python.testing.cwd'. The docs say that 'cwd' 'Specifies an optional working directory for unit tests.'.
Read more >
Settings Reference for Python - Visual Studio Code
Specifies whether to enable or disable auto run test discovery when saving a test file. Testing. unittest framework. Setting (python.testing.) Default ...
Read more >
Changing standard (Python) test discovery - Pytest
The --ignore-glob option allows to ignore test file paths based on Unix shell-style wildcards. If you want to exclude test-modules that end with...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
The command line can also be used for test discovery, for running all of the tests in a project or just a subset....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found