mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
Preserves the PyTest cache from one job run to the next. In a later PR, this will be used to change the order in which we actually run those tests The process is: 1. Before running tests, check S3 to see if there is an uploaded cache from any shard of the current job 2. If there are, download them all and merge their contents. Put the merged cache in the default .pytest_cache folder 3. After running the tests, merge the now-current .pytest_cache folder with the cache previously downloaded for the current shard. This will make the merged cache contain all tests that have ever failed for the given PR in the current shard 4. Upload the resulting cache file back to S3 The S3 folder has a retention policy of 30 days, after which the uploaded cache files will get auto-deleted. Pull Request resolved: https://github.com/pytorch/pytorch/pull/100522 Approved by: https://github.com/huydhn
85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
from unittest import main, TestCase
|
|
|
|
from pytest_caching_utils import _merged_lastfailed_content
|
|
|
|
|
|
class TestPytestCachingUtils(TestCase):
|
|
def test_merged_lastfailed_content_with_overlap(self) -> None:
|
|
last_failed_source = {
|
|
"tools/tests/test_foo.py::test_num1": True,
|
|
"tools/tests/test_foo.py::test_num2": True,
|
|
"tools/tests/test_bar.py::test_num1": True,
|
|
}
|
|
last_failed_dest = {
|
|
"tools/tests/test_foo.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
last_failed_merged = {
|
|
"tools/tests/test_foo.py::test_num1": True,
|
|
"tools/tests/test_foo.py::test_num2": True,
|
|
"tools/tests/test_bar.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
|
|
merged = _merged_lastfailed_content(last_failed_source, last_failed_dest)
|
|
self.assertEqual(merged, last_failed_merged)
|
|
|
|
def test_merged_lastfailed_content_without_overlap(self) -> None:
|
|
last_failed_source = {
|
|
"tools/tests/test_foo.py::test_num1": True,
|
|
"tools/tests/test_foo.py::test_num2": True,
|
|
"tools/tests/test_bar.py::test_num1": True,
|
|
}
|
|
last_failed_dest = {
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
last_failed_merged = {
|
|
"tools/tests/test_foo.py::test_num1": True,
|
|
"tools/tests/test_foo.py::test_num2": True,
|
|
"tools/tests/test_bar.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
|
|
merged = _merged_lastfailed_content(last_failed_source, last_failed_dest)
|
|
self.assertEqual(merged, last_failed_merged)
|
|
|
|
def test_merged_lastfailed_content_with_empty_source(self) -> None:
|
|
last_failed_source = {
|
|
"": True,
|
|
}
|
|
last_failed_dest = {
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
last_failed_merged = {
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
|
|
merged = _merged_lastfailed_content(last_failed_source, last_failed_dest)
|
|
self.assertEqual(merged, last_failed_merged)
|
|
|
|
def test_merged_lastfailed_content_with_empty_dest(self) -> None:
|
|
last_failed_source = {
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
last_failed_dest = {
|
|
"": True,
|
|
}
|
|
last_failed_merged = {
|
|
"tools/tests/test_car.py::test_num1": True,
|
|
"tools/tests/test_car.py::test_num2": True,
|
|
}
|
|
|
|
merged = _merged_lastfailed_content(last_failed_source, last_failed_dest)
|
|
self.assertEqual(merged, last_failed_merged)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|