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

Error when discovering tests with pytest in scikit-learn repo #7487

Closed
ogrisel opened this issue Sep 19, 2019 · 5 comments
Closed

Error when discovering tests with pytest in scikit-learn repo #7487

ogrisel opened this issue Sep 19, 2019 · 5 comments
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@ogrisel
Copy link

ogrisel commented Sep 19, 2019

Environment data

  • VS Code version: 1.39.0-insider
  • Extension version (available under the Extensions sidebar): 2019.9.34911 (3 September 2019)
  • OS and version: Linux x64 5.0.0-27
  • Python version (& distribution if applicable, e.g. Anaconda): python 3.7 from conda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda env
  • Relevant/affected Python packages and their versions: pytest 5.1.2
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version #3977): language server

Here is the error I get when I discover the tests from within VS code. I don't have any problem running pytest from the command line in the same source folder / conda env.

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/_pytest/main.py", line 440, in perform_collect
INTERNALERROR>     session=self, config=self.config, items=items
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 92, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 86, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 80, in pytest_collection_modifyitems
INTERNALERROR>     test, parents = self.parse_item(item)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 65, in parse_item
INTERNALERROR>     return parse_item(item)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 162, in parse_item
INTERNALERROR>     location, fullname = _get_location(item, testroot, relfile)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 143, in <lambda>
INTERNALERROR>     _get_location=(lambda *a: _get_location(*a)),
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 283, in _get_location
INTERNALERROR>     location = '{}:{}'.format(srcfile, int(lineno) + 1)
INTERNALERROR> TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
INTERNALERROR> 
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/_pytest/main.py", line 191, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/_pytest/main.py", line 234, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 92, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 86, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/_pytest/main.py", line 244, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/_pytest/main.py", line 443, in perform_collect
INTERNALERROR>     hook.pytest_collection_finish(session=self)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/hooks.py", line 286, in __call__
INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 92, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/manager.py", line 86, in <lambda>
INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 208, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 80, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/home/ogrisel/miniconda3/envs/pip/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 94, in pytest_collection_finish
INTERNALERROR>     test, parents = self.parse_item(item)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 65, in parse_item
INTERNALERROR>     return parse_item(item)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 162, in parse_item
INTERNALERROR>     location, fullname = _get_location(item, testroot, relfile)
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 143, in <lambda>
INTERNALERROR>     _get_location=(lambda *a: _get_location(*a)),
INTERNALERROR>   File "/home/ogrisel/.vscode-insiders/extensions/ms-python.python-2019.9.34911/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py", line 283, in _get_location
INTERNALERROR>     location = '{}:{}'.format(srcfile, int(lineno) + 1)
INTERNALERROR> TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Steps to reproduce:

  1. git clone https://github.com/scikit-learn/scikit-learn
  2. cd scikit-learn
  3. pip install -e .
  4. pip install -U pytest
  5. code-insiders .
  6. Configure test discovery with pytest and the scikit-learn root folder.
  7. Get the above failure in the output panel.
@ogrisel ogrisel added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 19, 2019
@kimadeline kimadeline self-assigned this Sep 19, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 19, 2019
@kimadeline
Copy link

Hi @ogrisel 👋 Thank you for reporting this!

We have issues with pytest 5.1 (see #6990), but I could reproduce your issue using pytest 5.0.1 (although, I'm on macOS so there were a few more steps involved when installing scikit-learn). I can also confirm that running python -m pytest --collect-only in the terminal directly works.

@kimadeline kimadeline added needs PR area-testing regression Bug didn't exist in a previous release and removed triage labels Sep 19, 2019
@kimadeline kimadeline removed their assignment Sep 19, 2019
@Nodd
Copy link

Nodd commented Nov 9, 2019

I have the same problem with a personal repository. My config is : Python 3.7.5, pytest-5.2.2, py-1.8.0, pluggy-0.13.0 on windows 10 64bits with conda. pytest works fine in a console.

@ogrisel
Copy link
Author

ogrisel commented Dec 5, 2019

Upon further inspection, the value of the item.location that triggers this bug is:

item.location == ('sklearn/_config.py', None, '[doctest] sklearn._config.config_context')

Maybe the lineno cannot be found because it is a doctest on a function that has the @context_manager decorator?

I will submit a PR with a quick fix.

@brettcannon
Copy link
Member

@karrtikr was this verified and so this can be closed?

@karrtikr
Copy link

Yeah we can close this

@ghost ghost removed the needs PR label Dec 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 6, 2020
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 regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

5 participants