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

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

Open
asottile opened this issue Jul 2, 2018 · 6 comments
Open

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

asottile opened this issue Jul 2, 2018 · 6 comments
Labels
plugin: debugging related to the debugging builtin plugin topic: collection related to the collection phase type: bug problem that needs to be addressed

Comments

@asottile
Copy link
Member

asottile commented Jul 2, 2018

$ 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?

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #1932 (pytest --pdb is no longer working with Flask_testing), #3245 (py.test on pytest fails when not limiting to the testing folder), #1411 (Pytest stops), #262 (--pdb drops you into pdb if you have an xfail), and #2574 (pytest --fixtures drops indentation from fixture docstring).

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jul 2, 2018
@Zac-HD Zac-HD added plugin: debugging related to the debugging builtin plugin type: question general question, might be closed after 2 weeks of inactivity and removed type: bug problem that needs to be addressed labels Oct 19, 2018
@Zac-HD
Copy link
Member

Zac-HD commented Oct 19, 2018

The except SyntaxError: line is responsible for the detailed traceback, which probably is desirable.

Entering the debugger is unrelated though, so we'd have to write a lot of new code to check why the debugger was being entered and conditionally skip it. IMO syntax errors with a debugger set are too rare to justify maintaining that extra code.

@Zac-HD Zac-HD closed this as completed Oct 19, 2018
@asottile
Copy link
Member Author

no no, this is definitely worth fixing

@asottile asottile reopened this Oct 19, 2018
@asottile asottile added type: bug problem that needs to be addressed and removed plugin: debugging related to the debugging builtin plugin type: question general question, might be closed after 2 weeks of inactivity labels Oct 19, 2018
@Tadaboody
Copy link
Contributor

I think that in general, debugger should not be launched in the collection phase

@blueyed blueyed added topic: collection related to the collection phase plugin: debugging related to the debugging builtin plugin labels Jan 8, 2019
@ernstki
Copy link

ernstki commented Oct 14, 2021

In the meantime, anyone stuck in this situation can press Ctrl+Z, then kill %; fg (assuming the Bash shell).

For some odd reason—not my area of expertise—just kill alone isn't enough. You have to bring the job back to the foreground for it to decide to die.

Edit: Ah, disregard, it was all pdbpp's fault. Uninstall that package and pytest --pdb seems to work as advertised, at least in the situation where I was getting stuck before.

@asottile
Copy link
Member Author

for me all I needed was q<Enter>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: debugging related to the debugging builtin plugin topic: collection related to the collection phase type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

6 participants