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

Fails to discover pytest tests in Pytest > 5.1.0 #7089

Closed
dillonm197 opened this issue Aug 23, 2019 · 1 comment
Closed

Fails to discover pytest tests in Pytest > 5.1.0 #7089

dillonm197 opened this issue Aug 23, 2019 · 1 comment
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@dillonm197
Copy link

I'm not sure if this is an issue with pytest so I'm logging it here for now. Tests fail to discover when using pytest >= 5.1.0 when pytest.ini or tox.ini are present in project.

I'd normally assume this was a pytest issue but if I execute the command to discover tests manually in terminal, it runs without error.

Environment data

  • VS Code version: 1.37.1
  • Extension version: 2019.9.32431-dev
  • OS and version: Windows 10 Pro (64 bit)
  • Python version: 3.7.3 32-bit
  • Relevant/affected Python packages and their versions: pytest >= 5.1.0

Expected behaviour

Test discovery passes.

Actual behaviour

Test discovery fails.

Steps to reproduce:

  1. Create a Python project that utilizes pytest.
  2. Add pytest.ini.
  3. Add conftest.py.
  4. In conftest.py add the following:
def pytest_addoption(parser):
    parser.addoption('--test', action='store', default='test', help='Test')
  1. Create a test file and add simple tests to it.
  2. Open the test tab and scan for tests.

Logs

python C:\Users\dillon.miller\.vscode\extensions\ms-python.python-2019.9.32431-dev\pythonFiles\testing_tools\run_adapter.py discover pytest -- -s --cache-clear tests
Test Discovery failed: 
Error: ============================= test session starts =============================
platform win32 -- Python 3.7.3, pytest-5.1.1, py-1.8.0, pluggy-0.12.0
rootdir: c:\Users\dillon.miller\Documents\act.nexus\e2e, inifile: tox.ini
plugins: flaky-3.6.1, check-0.3.5, html-1.22.0, instafail-0.4.1, metadata-1.8.0
________________________ ERROR collecting test session ________________________
Traceback (most recent call last):
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\__init__.py", line 436, in _importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('C:\\Users\\dillon.miller\\Documents\\act.nexus\\e2e\\conftest.py')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\py\_path\common.py", line 377, in visit
    for x in Visitor(fil, rec, ignore, bf, sort).gen(self):
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\py\_path\common.py", line 418, in gen
    dirs = self.optsort([p for p in entries
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\py\_path\common.py", line 419, in <listcomp>
    if p.check(dir=1) and (rec is None or rec(p))])
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\main.py", line 600, in _recurse
    ihook = self.gethookproxy(dirpath.dirpath())
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\main.py", line 424, in gethookproxy
    my_conftestmodules = pm._getconftestmodules(fspath)
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\__init__.py", line 420, in _getconftestmodules
    mod = self._importconftest(conftestpath.realpath())
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\__init__.py", line 461, in _importconftest
    self.consider_conftest(mod)
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\__init__.py", line 514, in consider_conftest
    self.register(conftestmodule, name=conftestmodule.__file__)
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\__init__.py", line 323, in register
    ret = super().register(plugin, name)
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\manager.py", line 121, in register
    hook._maybe_apply_history(hookimpl)
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\hooks.py", line 336, in _maybe_apply_history
    res = self._hookexec(self, [method], kwargs)
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\callers.py", line 208, in _multicall
    return outcome.get_result()
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "C:\Users\dillon.miller\AppData\Roaming\Python\Python37\site-packages\pluggy\callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "c:\Users\dillon.miller\Documents\act.nexus\e2e\conftest.py", line 86, in pytest_addoption
    help='Test')
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\argparsing.py", line 73, in addoption
    self._anonymous.addoption(*opts, **attrs)
  File "C:\Users\dillon.miller\AppData\Local\Programs\Python\Python37-32\lib\site-packages\_pytest\config\argparsing.py", line 304, in addoption
    raise ValueError("option names %s already added" % conflict)
ValueError: option names {'--test'} already added
collected 0 items / 1 errors

- generated html file: file://c:\Users\dillon.miller\Documents\act.nexus\e2e\pytest-results.html -
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.23s ===============================

Traceback (most recent call last):
  File "C:\Users\dillon.miller\.vscode\extensions\ms-python.python-2019.9.32431-dev\pythonFiles\testing_tools\run_adapter.py", line 18, in <module>
    main(tool, cmd, subargs, toolargs)
  File "C:\Users\dillon.miller\.vscode\extensions\ms-python.python-2019.9.32431-dev\pythonFiles\testing_tools\adapter\__main__.py", line 90, in main
    parents, result = run(toolargs, **subargs)
  File "C:\Users\dillon.miller\.vscode\extensions\ms-python.python-2019.9.32431-dev\pythonFiles\testing_tools\adapter\pytest\_discovery.py", line 35, in discover
    raise Exception('pytest discovery failed (exit code {})'.format(ec))
Exception: pytest discovery failed (exit code 2)
@dillonm197 dillonm197 added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Aug 23, 2019
@ericsnowcurrently
Copy link
Member

Thanks for letting us know about this. We are aware of the issue and addressing it in #6990.

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 2, 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
Projects
None yet
Development

No branches or pull requests

2 participants