pytest-dev / pytest-dev/pytest
pytest syntax_error.py --pdb should not drop into pdb?
Open
Nobody has claimed this yet.
plugin: debugging
topic: collection
type: bug
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
$ pytest --version
This is pytest version 3.6.2, imported from /private/tmp/x/venv/lib/python3.6/site-packages/pytest.py
# t.py
syntax error
$ pytest t.py --pdb
============================ test session starts =============================
platform darwin -- Python 3.6.5, pytest-3.6.2, py-1.5.4, pluggy-0.6.0
rootdir: /private/tmp/x, inifile:
collecting 0 items
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
venv/lib/python3.6/site-packages/_pytest/python.py:468: in _importtestmodule
mod = self.fspath.pyimport(ensuresyspath=importmode)
venv/lib/python3.6/site-packages/py/_path/local.py:668: in pyimport
__import__(modname)
E File "/private/tmp/x/t.py", line 1
E syntax error
E ^
E SyntaxError: invalid syntax
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> entering PDB >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /private/tmp/x/venv/lib/python3.6/site-packages/_pytest/python.py(471)_importtestmodule()
-> _pytest._code.ExceptionInfo().getrepr(style="short")
(Pdb) list
466 importmode = self.config.getoption("--import-mode")
467 try:
468 mod = self.fspath.pyimport(ensuresyspath=importmode)
469 except SyntaxError:
470 raise self.CollectError(
471 -> _pytest._code.ExceptionInfo().getrepr(style="short")
472 )
473 except self.fspath.ImportMismatchError:
474 e = sys.exc_info()[1]
475 raise self.CollectError(
476 "import file mismatch:\n"
(Pdb) q
collected 0 items / 1 errors
!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!
========================== 1 error in 8.44 seconds ===========================
as far as I can tell, it has always done this -- is this a desirable behaviour?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with pytest --pdb and the shown t.py containing a syntax error. Then read _pytest/python.py around _importtestmodule and trace how collection errors interact with --pdb. The issue does not define the desired replacement behavior, so completion requires agreeing on that behavior and adding coverage for the chosen outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100