pytest-dev / pytest-dev/pytest

pytest syntax_error.py --pdb should not drop into pdb?

Open
#3,649 6 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.