-
- Notifications
You must be signed in to change notification settings - Fork 2.9k
3610 add trace option #3647
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
nicoddemus merged 18 commits into pytest-dev:features from jeffreyrack:3610-add-trace-option Jul 7, 2018
Merged
3610 add trace option #3647
Changes from 11 commits
Commits
Show all changes
18 commits Select commit Hold shift + click to select a range
54d3cd5 Adding the --trace option.
jeffreyrack 952bbef Add initial test.
jeffreyrack a46b949 Properly set immediately_break value
jeffreyrack 533f4cc Fix test to pass
jeffreyrack 57198d4 Adding changelog entry for the --trace option.
jeffreyrack 713d32c Adding documentation for the --trace option.
jeffreyrack 66fa6bb Fix flake8 issues.
jeffreyrack a604a71 Fixing usage.rst title.
jeffreyrack 8801162 Fixing tabbing in usage.rst.
jeffreyrack 0b70477 Fix linting issues.
jeffreyrack bc268a5 Adding needed newline
jeffreyrack b75320b Fix --trace option with yield tests.
jeffreyrack 10a8691 Add support for yielded functions.
jeffreyrack 6cc4fe2 Fixing bad indentation
jeffreyrack 2f1a2cf Fixing --trace test.
jeffreyrack 4afb8c4 Fix python 2 issues
jeffreyrack 4a925ef Fixing bug in test.
jeffreyrack 067de25 Fix test_pdb.py with pexpect
jeffreyrack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added the `--trace` option to enter the debugger at the start of a test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -5,6 +5,8 @@ | |
| import os | ||
| from doctest import UnexpectedException | ||
| | ||
| from _pytest.config import hookimpl | ||
| | ||
| try: | ||
| from builtins import breakpoint # noqa | ||
| | ||
| | @@ -13,6 +15,9 @@ | |
| SUPPORTS_BREAKPOINT_BUILTIN = False | ||
| | ||
| | ||
| immediately_break = False | ||
| | ||
| | ||
| def pytest_addoption(parser): | ||
| group = parser.getgroup("general") | ||
| group._addoption( | ||
| | @@ -28,6 +33,12 @@ def pytest_addoption(parser): | |
| help="start a custom interactive Python debugger on errors. " | ||
| "For example: --pdbcls=IPython.terminal.debugger:TerminalPdb", | ||
| ) | ||
| group._addoption( | ||
| "--trace", | ||
| dest="trace", | ||
| action="store_true", | ||
| help="Immediately break when running each test.", | ||
| ) | ||
| | ||
| | ||
| def pytest_configure(config): | ||
| | @@ -38,6 +49,8 @@ def pytest_configure(config): | |
| else: | ||
| pdb_cls = pdb.Pdb | ||
| | ||
| global immediately_break | ||
| immediately_break = config.getvalue("trace") | ||
| if config.getvalue("usepdb"): | ||
| config.pluginmanager.register(PdbInvoke(), "pdbinvoke") | ||
| | ||
| | @@ -63,6 +76,24 @@ def fin(): | |
| config._cleanup.append(fin) | ||
| | ||
| | ||
| @hookimpl(hookwrapper=True) | ||
| def pytest_pyfunc_call(pyfuncitem): | ||
| if immediately_break: | ||
| pytestPDB.set_trace(set_break=False) | ||
| testfunction = pyfuncitem.obj | ||
| pyfuncitem.obj = pdb.runcall | ||
| if pyfuncitem._isyieldedfunction(): | ||
| pyfuncitem.args = [testfunction, pyfuncitem._args] | ||
jeffreyrack marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| else: | ||
| if "func" in pyfuncitem._fixtureinfo.argnames: | ||
| ||
| raise ValueError("--trace can't be used with a fixture named func!") | ||
| pyfuncitem.funcargs["func"] = testfunction | ||
| new_list = list(pyfuncitem._fixtureinfo.argnames) | ||
| new_list.append("func") | ||
| pyfuncitem._fixtureinfo.argnames = tuple(new_list) | ||
| yield | ||
| | ||
| | ||
| class pytestPDB(object): | ||
| """ Pseudo PDB that defers to the real pdb. """ | ||
| | ||
| | @@ -71,7 +102,7 @@ class pytestPDB(object): | |
| _pdb_cls = pdb.Pdb | ||
| | ||
| @classmethod | ||
| def set_trace(cls): | ||
| def set_trace(cls, set_break=True): | ||
| """ invoke PDB set_trace debugging, dropping any IO capturing. """ | ||
| import _pytest.config | ||
| | ||
| | @@ -84,7 +115,8 @@ def set_trace(cls): | |
| tw.line() | ||
| tw.sep(">", "PDB set_trace (IO-capturing turned off)") | ||
| cls._pluginmanager.hook.pytest_enter_pdb(config=cls._config) | ||
| cls._pdb_cls().set_trace(frame) | ||
| if set_break: | ||
| cls._pdb_cls().set_trace(frame) | ||
| | ||
| | ||
| class PdbInvoke(object): | ||
| | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be a option to the pdbinvoke plugin, which then could handle the pyfunc_call