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

Cannot run unittests discovered with --pattern flag #8465

Closed
eirki opened this issue Nov 8, 2019 · 2 comments
Closed

Cannot run unittests discovered with --pattern flag #8465

eirki opened this issue Nov 8, 2019 · 2 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug good first issue

Comments

@eirki
Copy link

eirki commented Nov 8, 2019

Environment data

  • VS Code version: 1.39.2
  • Extension version : 2019.10.44104
  • OS and version: Ubuntu 18.04 / Windows 10
  • Python version: Python 3.7
  • Type of virtual environment used): Tested with venv and without any environment
  • Relevant/affected Python packages and their versions: unittest

Expected behaviour

Python: Run all tests should run tests that have been discovered.

Actual behaviour

Tests are discovered, but when I select Run all tests, no tests run.

Steps to reproduce:

Very basic (but non-standard) file structure:

root
├───.vscode
│       settings.json
│
└───testdir
    │   file.py

Contents of settings.json:

{
    "python.testing.pytestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.unittestEnabled": true,
    "python.testing.unittestArgs": [
        "discover",
        "--start-directory",
        "./testdir/",
        "--pattern",
        "*.py",
    ]
}

Contents of file.py

import unittest

class MyTest(unittest.TestCase):
    def test_0(self):
        self.assertTrue(True)

Logs

Output for Python in the Output panel

> ~\AppData\Local\Microsoft\WindowsApps\python3.exe ~\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\interpreterInfo.py
Starting Jedi Python language engine.
> C:\Program Files\Python37\python.exe -c "
import unittest
loader = unittest.TestLoader()
suites = loader.discover("./testdir/", pattern="*.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: <path>
> C:\Program Files\Python37\python.exe ~\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\visualstudio_py_testlauncher.py --us=./testdir/ --up=test*.py --uvInt=1 --result-port=57380
cwd: <path>

(Notice the argument to visualstudio_py_testlauncher.py is --up=test*.py. This is the default pattern, not "*.py" as specified in the settings.json)

Output from Python Test Log

start
file.MyTest.test_0

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

However, when I change "--pattern" to "-p" and try to re-run the tests, it works:

Python Log:

> C:\Program Files\Python37\python.exe ~\.vscode\extensions\ms-python.python-2019.10.41019\pythonFiles\visualstudio_py_testlauncher.py --us=./testdir/ --up=*.py --uvInt=1 --result-port=58052
cwd: c:\Users\ebs\Dropbox\Programmering\vsunittests

(Now visualstudio_py_testlauncher.py get's the correct argument, --up=*.py, )

Python Test Log:

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

I think I've found the source of the bug in this line, which tries to parse the argument '-pattern', and not '--pattern'. I changed it manually in the compiled extension.js file and that seemed to fix it. I'd be happy to try to and fix it in the source and submit a PR, but I am not very TypeScript proficient.

@eirki eirki added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Nov 8, 2019
@karthiknadig karthiknadig self-assigned this Nov 11, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Nov 11, 2019
@brettcannon
Copy link
Member

Thanks for the bug report! We just wanted to acknowledge that we got the report, triaged it, and have determined it is a bug.

@karrtikr
Copy link

validated

@ghost ghost removed the needs PR label Nov 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug good first issue
Projects
None yet
Development

No branches or pull requests

6 participants