Skip to content

Commit

Permalink
add test for rerunfailures arg
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd committed Nov 21, 2024
1 parent 4e2d458 commit a7f749b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ def test_flaky(): # test_marker--test_flaky
os.environ["COUNT"] = "2"
# this will fail on the first run, but pass on the second (1 passed, 1 rerun)
assert count == "2"

def test_flaky_no_marker():
# this test is flaky and will be run via the command line argument
# count is not set for first run, but set to 2 for the second run
count = os.environ.get("COUNT")
os.environ["COUNT"] = "2"
# this will fail on the first run, but pass on the second (1 passed, 1 rerun)
assert count == "2"
15 changes: 15 additions & 0 deletions python_files/tests/pytestadapter/expected_execution_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,3 +749,18 @@
"subtest": None,
}
}

test_rerunfailures_plugin_path = TEST_DATA_PATH / "test_rerunfailures_plugin.py"
rerunfailures_with_arg_expected_execution_output = {
get_absolute_test_id(
"test_rerunfailures_plugin.py::test_flaky_no_marker", test_rerunfailures_plugin_path
): {
"test": get_absolute_test_id(
"test_rerunfailures_plugin.py::test_flaky_no_marker", test_rerunfailures_plugin_path
),
"outcome": "success",
"message": None,
"traceback": None,
"subtest": None,
}
}
17 changes: 17 additions & 0 deletions python_files/tests/pytestadapter/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ def test_rootdir_specified():
assert actual_result_dict == expected_const


def test_rerunfailure_with_arg():
"""Test pytest execution when a --rootdir is specified."""
args = ["--reruns=2", "test_rerunfailures_plugin.py::test_flaky_no_marker"]
actual = runner(args)
expected_const = expected_execution_test_output.rerunfailures_with_arg_expected_execution_output
assert actual
actual_list: List[Dict[str, Dict[str, Any]]] = actual
assert len(actual_list) == len(expected_const)
actual_result_dict = {}
if actual_list is not None:
for actual_item in actual_list:
assert all(item in actual_item for item in ("status", "cwd", "result"))
assert actual_item.get("status") == "success"
actual_result_dict.update(actual_item["result"])
assert actual_result_dict == expected_const


@pytest.mark.parametrize(
("test_ids", "expected_const"),
[
Expand Down

0 comments on commit a7f749b

Please sign in to comment.