This repository was archived by the owner on Sep 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 814
Create pytest fixture to auto delete model checkpoints within integration tests #1886
Merged
Nayef211
merged 9 commits into
pytorch:main
from
Nayef211:test/delete_checkpoints_after_integration_test
Sep 1, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
804b43a
Delete checkpoints after integration test
Nayef211 7ae058d
Use pytest fixtures to autodelete model assets in integration tests
Nayef211 8694c20
Created new unittest directory and new workflow for integration tests
Nayef211 2790120
Revert "Created new unittest directory and new workflow for integrati…
Nayef211 75fda73
Remove commented code
Nayef211 357d233
Add same contents to several conftest files
Nayef211 3ae6fe0
Deleted 2nd conftest file
Nayef211 4447b3b
Fix accessing pytest configs
Nayef211 0bc0136
Remove autouse from pytest fixture
Nayef211 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,28 @@ | ||
| import shutil | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
|
|
||
| def pytest_addoption(parser): | ||
| parser.addoption( | ||
| "--use-tmp-hub-dir", | ||
| action="store_true", | ||
| help=( | ||
| "When provided, tests will use temporary directory as Torch Hub directory. " | ||
| "Downloaded models will be deleted after each test." | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def temp_hub_dir(tmp_path_factory, pytestconfig): | ||
| if not pytestconfig.getoption("--use-tmp-hub-dir"): | ||
| yield | ||
| else: | ||
| tmp_dir = tmp_path_factory.mktemp("hub", numbered=True).resolve() | ||
| org_dir = torch.hub.get_dir() | ||
| torch.hub.set_dir(tmp_dir) | ||
| yield | ||
| torch.hub.set_dir(org_dir) | ||
| shutil.rmtree(tmp_dir, ignore_errors=True) | ||
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
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.
Follow-up in #1889 aside, I don't understand how this can work at all.
Both
tmp_path_factoryandpytestconfigappear nowhere else in the code base (as far as GH search andgit grepgo, at least), and based on the pytest docs this should probably bebut that still leaves me mystified as to where
tmp_path_factoryis coming from.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.
Ah, just found that it's a fixture that comes with pytest by default.
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.
OK, and so's
pytestconfig. In any case, my suspicion now is that this only works when called from within theintegration_testsfolder, because (I guess) recursiveconftest.pys are not evaluated when the CLI is called from a folder that's further out.Uh oh!
There was an error while loading. Please reload this page.
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.
@h-vetinari yup I think your understanding is correct. Does only being able to run this test from within the
integration_testsfolder pose an issue for adding torchtext toconda-forge?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.
No, I just had to realise the reason, after that it's simple. ;)