-
Notifications
You must be signed in to change notification settings - Fork 12
Patch tmp_path/tmpdir to be thread-safe #120
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
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
806200b
tmp_path fixture patched to be thread-safe
bwhitt7 4db300d
Create tests for tmp_path/tmpdir
bwhitt7 8dc8ce4
Add tmp_path/tmpdir changes to README
bwhitt7 f79c35b
New tmp_path test param
bwhitt7 e36186c
Modify tmp_path patches
bwhitt7 121c82d
Remove iteration support for tmp_path
bwhitt7 1a37a5d
tmp_path README iteration update
bwhitt7 2df77e9
Bring iteration support back
bwhitt7 3e1e203
Remove iteration support again
bwhitt7 41214f9
Fix comment in test_tmp_path_tmpdir
bwhitt7 2cf1300
Handle if directories already exist
bwhitt7 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
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,158 @@ | ||
| import pytest | ||
|
|
||
| parallel_iterations = [ | ||
| (1, 1, "PASSED"), # no parallel threads, no iterations | ||
| ("auto", 1, "PARALLEL PASSED"), # parallel threads, no iterations | ||
| (1, 5, "PASSED"), # no parallel threads, iterations | ||
| ("auto", 5, "PARALLEL PASSED"), # parallel threads and iterations | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmp_path_is_empty(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures tmp_path is empty for each thread/iteration | ||
| # test from (gh-109) | ||
| pytester.makepyfile(""" | ||
| def test_tmp_path(tmp_path): | ||
| assert tmp_path.exists() | ||
| assert tmp_path.is_dir() | ||
| assert len(list(tmp_path.iterdir())) == 0 | ||
| d = tmp_path / "sub" | ||
| assert not d.exists() | ||
| d.mkdir() | ||
| assert d.exists() | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmp_path {passing}*", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmp_path_read_write(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures we can read/write in each tmp_path | ||
| pytester.makepyfile(""" | ||
| def test_tmp_path(tmp_path): | ||
| file = tmp_path / "file" | ||
| with open(file, "w") as f: | ||
| f.write("Hello world!") | ||
| assert file.is_file() | ||
| assert file.read_text() == "Hello world!" | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmp_path {passing}*", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmp_path_delete(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures we can delete files in each tmp_path | ||
| pytester.makepyfile(""" | ||
| def test_tmp_path(tmp_path): | ||
| subdir = tmp_path / "subdir" | ||
| subdir.mkdir() | ||
| file = subdir / "file" | ||
| with open(file, "w") as f: | ||
| f.write("Hello world!") | ||
| assert file.is_file() | ||
| file.unlink() | ||
| assert not file.exists() | ||
| subdir.rmdir() | ||
| assert not subdir.exists() | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmp_path {passing}*", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmpdir_is_empty(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures tmpdir is empty for each thread/iteration | ||
| pytester.makepyfile(""" | ||
| def test_tmpdir(tmpdir): | ||
| assert tmpdir.check() | ||
| assert tmpdir.check(dir=1) | ||
| assert len(list(tmpdir.listdir())) == 0 | ||
| assert not tmpdir.join("sub").check() | ||
| assert tmpdir.mkdir("sub").check() | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmpdir {passing}*", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmpdir_read_write(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures we can read/write in each tmpdir | ||
| pytester.makepyfile(""" | ||
| def test_tmpdir(tmpdir): | ||
| file = tmpdir.join("file") | ||
| with open(file, "w") as f: | ||
| f.write("Hello world!") | ||
| assert file.check(file=1) | ||
| assert file.read_text("utf-8") == "Hello world!" | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmpdir {passing}*", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("parallel, iterations, passing", parallel_iterations) | ||
| def test_tmpdir_delete(pytester: pytest.Pytester, parallel, iterations, passing): | ||
| # ensures we can delete files in each tmpdir | ||
| pytester.makepyfile(""" | ||
| def test_tmpdir(tmpdir): | ||
| subdir = tmpdir.mkdir("sub") | ||
| file = tmpdir.join("file") | ||
| with open(file, "w") as f: | ||
| f.write("Hello world!") | ||
| assert file.check(file=1) | ||
| file.remove() | ||
| assert not file.check() | ||
| subdir.remove() | ||
| assert not subdir.check() | ||
| """) | ||
|
|
||
| result = pytester.runpytest( | ||
| f"--parallel-threads={parallel}", f"--iterations={iterations}", "-v" | ||
| ) | ||
|
|
||
| result.stdout.fnmatch_lines( | ||
| [ | ||
| f"*::test_tmpdir {passing}*", | ||
| ] | ||
| ) |
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.