Skip to content

Don't break into pdb when raise unittest.SkipTest() appears top-level in a file #10383

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

Merged

Conversation

gabriellandau
Copy link
Contributor

@gabriellandau gabriellandau commented Oct 14, 2022

Closes #10382

Don't break into pdb when raise unittest.SkipTest() appears top-level in a file.

I attempted to follow the instructions here. Please let me know if I missed anything.

I can't run the pytests directly, so let's see what CI says once I open this PR. Both the pip and tox instructions fail with a minversion error:

tox error
(venv) user@virtual-machine:~/pytest$ git checkout main
Already on 'main'
Your branch is up to date with 'origin/main'.
(venv) user@virtual-machine:~/pytest$ git rev-parse HEAD
15ac0349b2c7d8dc48fe2e25a1b4fa47c9fda25c
(venv) user@virtual-machine:~/pytest$ tox -e linting,py310
/home/user/pytest/.tox/.package/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
  warnings.warn(msg, warning_class)
/home/user/pytest/.tox/.package/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
  warnings.warn(msg, warning_class)
linting installed: cfgv==3.3.1,distlib==0.3.6,filelock==3.8.0,identify==2.5.6,nodeenv==1.7.0,platformdirs==2.5.2,pre-commit==2.20.0,PyYAML==6.0,toml==0.10.2,virtualenv==20.16.5
linting run-test-pre: PYTHONHASHSEED='3208460783'
linting run-test: commands[0] | pre-commit run --all-files --show-diff-on-failure
black....................................................................Passed
blacken-docs.............................................................Passed
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
fix python encoding pragma...............................................Passed
check yaml...............................................................Passed
debug statements (python)................................................Passed
autoflake................................................................Passed
flake8...................................................................Passed
Reorder python imports...................................................Passed
pyupgrade................................................................Passed
setup-cfg-fmt............................................................Passed
type annotations not comments............................................Passed
mypy.....................................................................Passed
rst......................................................................Passed
changelog filenames..................................(no files to check)Skipped
py library is deprecated.................................................Passed
py.path usage is deprecated..............................................Passed
py310 inst-nodeps: /home/user/pytest/.tox/.tmp/package/1/pytest-0.1.dev14703+g15ac034.tar.gz
py310 installed: argcomplete==2.0.0,attrs==22.1.0,certifi==2022.9.24,charset-normalizer==2.1.1,elementpath==3.0.2,exceptiongroup==1.0.0rc9,hypothesis==6.56.2,idna==3.4,iniconfig==1.1.1,mock==4.0.3,nose==1.3.7,packaging==21.3,pluggy==1.0.0,py==1.11.0,Pygments==2.13.0,pyparsing==3.0.9,pytest @ file:///home/user/pytest/.tox/.tmp/package/1/pytest-0.1.dev14703%2Bg15ac034.tar.gz,requests==2.28.1,sortedcontainers==2.4.0,tomli==2.0.1,urllib3==1.26.12,xmlschema==2.1.1
py310 run-test-pre: PYTHONHASHSEED='3208460783'
py310 run-test: commands[0] | pytest
ERROR: /home/user/pytest/pyproject.toml: 'minversion' requires pytest-2.0, actual pytest-0.1.dev14703+g15ac034'

ERROR: InvocationError for command /home/user/pytest/.tox/py310/bin/pytest (exited with code 4)
_______________________________________________________________________________________________ summary ________________________________________________________________________________________________
  linting: commands succeeded
ERROR:   py310: commands failed
(venv) user@virtual-machine:~/pytest$

I verified the undesirable behavior is remedied when I install via python3 setup.py develop and test a minimal repro file as documented in the original bug ticket.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Comment on lines +298 to +299
if not isinstance(call.excinfo.value, unittest.SkipTest):
_enter_pdb(node, call.excinfo, report)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that we still do enter pdb if unittest.SkipTest is raised within a test function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should enter pdb in that case? I would argue we shouldn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks for promptly reviewing this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the python docs:

Skipping a test is simply a matter of using the skip() decorator or one of its conditional variants, calling TestCase.skipTest() within a setUp() or test method, or raising SkipTest directly.

If those three actions are functionally equivalent, and we don't break into pdb for the skip() decorator, then it seems like we shouldn't break into pdb for raising SkipTest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yep, skipping both is consistent with the behavior of pytest.skip() too. Merging 🚀

@Zac-HD Zac-HD merged commit 3dac833 into pytest-dev:main Oct 15, 2022
@gabriellandau gabriellandau deleted the dont-pdb-break-for-skiptest-exceptions branch October 15, 2022 19:40
@gabriellandau
Copy link
Contributor Author

Thanks @Zac-HD!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--pdb breaks on raise unittest.SkipTest()
2 participants