-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
pytester: use monkeypatch.chdir() for dir changing
#11315
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The :fixture:`pytester` fixture now uses the :fixture:`monkeypatch` fixture to manage the current working directory. | ||
| If you use ``pytester`` in combination with :func:`monkeypatch.undo() <pytest.MonkeyPatch.undo>`, the CWD might get restored. | ||
| Use :func:`monkeypatch.context() <pytest.MonkeyPatch.context>` instead. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -854,7 +854,11 @@ def entry(): | |
| reprtb = p.repr_traceback(excinfo) | ||
| assert len(reprtb.reprentries) == 3 | ||
|
|
||
| def test_traceback_short_no_source(self, importasmod, monkeypatch) -> None: | ||
| def test_traceback_short_no_source( | ||
| self, | ||
| importasmod, | ||
| monkeypatch: pytest.MonkeyPatch, | ||
| ) -> None: | ||
| mod = importasmod( | ||
| """ | ||
| def func1(): | ||
|
|
@@ -866,14 +870,14 @@ def entry(): | |
| excinfo = pytest.raises(ValueError, mod.entry) | ||
| from _pytest._code.code import Code | ||
|
|
||
| monkeypatch.setattr(Code, "path", "bogus") | ||
| p = FormattedExcinfo(style="short") | ||
| reprtb = p.repr_traceback_entry(excinfo.traceback[-2]) | ||
| lines = reprtb.lines | ||
| last_p = FormattedExcinfo(style="short") | ||
| last_reprtb = last_p.repr_traceback_entry(excinfo.traceback[-1], excinfo) | ||
| last_lines = last_reprtb.lines | ||
| monkeypatch.undo() | ||
| with monkeypatch.context() as mp: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because others use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - added a changelog. |
||
| mp.setattr(Code, "path", "bogus") | ||
| p = FormattedExcinfo(style="short") | ||
| reprtb = p.repr_traceback_entry(excinfo.traceback[-2]) | ||
| lines = reprtb.lines | ||
| last_p = FormattedExcinfo(style="short") | ||
| last_reprtb = last_p.repr_traceback_entry(excinfo.traceback[-1], excinfo) | ||
| last_lines = last_reprtb.lines | ||
| assert lines[0] == " func1()" | ||
|
|
||
| assert last_lines[0] == ' raise ValueError("hello")' | ||
|
|
||
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.
should we log a followup to ensure sys.path/sys.modules handling in coordination with monkeypatch
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.
Might be possible but some complications:
SysPathSnapshotalso savessys.meta_path, monkeypatch doesn't.sys.pathby default, though pytester can probably force it to do itSysModulesSnapshothas no equivalent in monkeypatch currenty as far as know. Also has somepreserve_modulesexclusion...