Skip to content

Commit a7f749b

Browse files
committed
add test for rerunfailures arg
1 parent 4e2d458 commit a7f749b

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

python_files/tests/pytestadapter/.data/test_rerunfailures_plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ def test_flaky(): # test_marker--test_flaky
1111
os.environ["COUNT"] = "2"
1212
# this will fail on the first run, but pass on the second (1 passed, 1 rerun)
1313
assert count == "2"
14+
15+
def test_flaky_no_marker():
16+
# this test is flaky and will be run via the command line argument
17+
# count is not set for first run, but set to 2 for the second run
18+
count = os.environ.get("COUNT")
19+
os.environ["COUNT"] = "2"
20+
# this will fail on the first run, but pass on the second (1 passed, 1 rerun)
21+
assert count == "2"

python_files/tests/pytestadapter/expected_execution_test_output.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,3 +749,18 @@
749749
"subtest": None,
750750
}
751751
}
752+
753+
test_rerunfailures_plugin_path = TEST_DATA_PATH / "test_rerunfailures_plugin.py"
754+
rerunfailures_with_arg_expected_execution_output = {
755+
get_absolute_test_id(
756+
"test_rerunfailures_plugin.py::test_flaky_no_marker", test_rerunfailures_plugin_path
757+
): {
758+
"test": get_absolute_test_id(
759+
"test_rerunfailures_plugin.py::test_flaky_no_marker", test_rerunfailures_plugin_path
760+
),
761+
"outcome": "success",
762+
"message": None,
763+
"traceback": None,
764+
"subtest": None,
765+
}
766+
}

python_files/tests/pytestadapter/test_execution.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ def test_rootdir_specified():
6565
assert actual_result_dict == expected_const
6666

6767

68+
def test_rerunfailure_with_arg():
69+
"""Test pytest execution when a --rootdir is specified."""
70+
args = ["--reruns=2", "test_rerunfailures_plugin.py::test_flaky_no_marker"]
71+
actual = runner(args)
72+
expected_const = expected_execution_test_output.rerunfailures_with_arg_expected_execution_output
73+
assert actual
74+
actual_list: List[Dict[str, Dict[str, Any]]] = actual
75+
assert len(actual_list) == len(expected_const)
76+
actual_result_dict = {}
77+
if actual_list is not None:
78+
for actual_item in actual_list:
79+
assert all(item in actual_item for item in ("status", "cwd", "result"))
80+
assert actual_item.get("status") == "success"
81+
actual_result_dict.update(actual_item["result"])
82+
assert actual_result_dict == expected_const
83+
84+
6885
@pytest.mark.parametrize(
6986
("test_ids", "expected_const"),
7087
[

0 commit comments

Comments
 (0)