-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Tmpdir port pathlib #3988
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 25 commits into
pytest-dev:features
from
RonnyPfannschmidt:tmpdir-port-pathlib
Oct 12, 2018
Merged
Tmpdir port pathlib #3988
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b48e23d
port interals of tmpdir to a basic pathlib implementation
RonnyPfannschmidt 2e39fd8
add python27 support by using reduce instead of max
RonnyPfannschmidt d053cdf
factor out max and iterate on locks and cleanups
RonnyPfannschmidt 8e00280
fix linting
RonnyPfannschmidt 66a6909
bring in purepath and fix an assertion
RonnyPfannschmidt ab3637d
implement cleanup for unlocked folders
RonnyPfannschmidt 8b4a293
fix typo
RonnyPfannschmidt b3a5b0e
remove path from exposure
RonnyPfannschmidt 642cd86
shape up removal and lock destruction
RonnyPfannschmidt 2532dc1
fix up lock consideration argument
RonnyPfannschmidt d76fa59
fix lock timeouts for good this time
RonnyPfannschmidt fed4f73
ignore rmtree errors
RonnyPfannschmidt 85cc9b8
move all the things into _pytest.pathlib
RonnyPfannschmidt 0071617
fix missed Path import
RonnyPfannschmidt 2831cb9
unify paths.py and pathlib.py
RonnyPfannschmidt 3036914
sort out rmtree expectations
RonnyPfannschmidt ad6f63e
add changelog
RonnyPfannschmidt 4a436b5
resolve in code review commments
RonnyPfannschmidt b82d6f7
pytester: use per test tmproot
RonnyPfannschmidt 94829c3
make tmpdir env cleanup idempotent
RonnyPfannschmidt ebd597b
use the constant for lock timeouts
RonnyPfannschmidt 36c2a10
add missing docstring
RonnyPfannschmidt 16e2737
implement tmp_path_factory and deprecate pytest.ensuretemp as intended
RonnyPfannschmidt 584051a
extend docs with basics about tmp_path and tmp_path_facotry
RonnyPfannschmidt 4736b2b
address review comments
RonnyPfannschmidt 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
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 @@ | ||
Introduce ``tmp_path`` as a fixture providing a Path 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a Deprecation warning for pytest.ensuretemp as it was deprecated since a while. |
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 @@ | ||
Port the implementation of tmpdir to pathlib. |
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,55 @@ | |
Temporary directories and files | ||
================================================ | ||
|
||
The ``tmp_path`` fixture | ||
------------------------ | ||
|
||
.. versionadded:: 3.9 | ||
|
||
|
||
You can use the ``tmpdir`` fixture which will | ||
provide a temporary directory unique to the test invocation, | ||
created in the `base temporary directory`_. | ||
|
||
``tmpdir`` is a ``pathlib/pathlib2.Path`` object. Here is an example test usage: | ||
|
||
.. code-block:: python | ||
|
||
# content of test_tmp_path.py | ||
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. I believe it is better to use |
||
import os | ||
|
||
CONTENT = u"content" | ||
|
||
|
||
def test_create_file(tmp_path): | ||
d = tmp_path / "sub" | ||
d.mkdir() | ||
p = d / "hello.txt" | ||
p.write_text(CONTENT) | ||
assert p.read_text() == CONTENT | ||
assert len(tmpdir.listdir()) == 1 | ||
assert 0 | ||
|
||
Running this would result in a passed test except for the last | ||
``assert 0`` line which we use to look at values:: | ||
|
||
$ pytest test_tmp_path.py | ||
... #fill fom regendoc | ||
|
||
|
||
|
||
The ``tmp_path_factory`` fixture | ||
-------------------------------- | ||
|
||
.. versionadded:: 3.9 | ||
|
||
|
||
The ``tmp_path_facotry`` is a session-scoped fixture which can be used | ||
Zac-HD marked this conversation as resolved.
Show resolved
Hide resolved
|
||
to create arbitrary temporary directories from any other fixture or test. | ||
|
||
its intended to replace ``tmpdir_factory`` and returns :class:`pathlib.Path` instances. | ||
|
||
|
||
The 'tmpdir' fixture | ||
-------------------- | ||
|
||
|
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
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 |
---|---|---|
|
@@ -109,3 +109,8 @@ | |
PYTEST_NAMESPACE = RemovedInPytest4Warning( | ||
"pytest_namespace is deprecated and will be removed soon" | ||
) | ||
|
||
PYTEST_ENSURETEMP = RemovedInPytest4Warning( | ||
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. We should add a |
||
"pytest/tmpdir_factory.ensuretemp is deprecated, \n" | ||
"please use the tmp_path fixture or tmp_path_factory.mktemp" | ||
) |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.