diff --git a/python_files/tests/pytestadapter/.data/test_rerunfailures_plugin.py b/python_files/tests/pytestadapter/.data/test_rerunfailures_plugin.py index 93d58378ffa1..7f152cbb68c4 100644 --- a/python_files/tests/pytestadapter/.data/test_rerunfailures_plugin.py +++ b/python_files/tests/pytestadapter/.data/test_rerunfailures_plugin.py @@ -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" diff --git a/python_files/tests/pytestadapter/expected_execution_test_output.py b/python_files/tests/pytestadapter/expected_execution_test_output.py index 8ea2fe1f1c0b..0d8e9af943f3 100644 --- a/python_files/tests/pytestadapter/expected_execution_test_output.py +++ b/python_files/tests/pytestadapter/expected_execution_test_output.py @@ -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, + } +} diff --git a/python_files/tests/pytestadapter/test_execution.py b/python_files/tests/pytestadapter/test_execution.py index af34fdc07b01..746a86dca9bd 100644 --- a/python_files/tests/pytestadapter/test_execution.py +++ b/python_files/tests/pytestadapter/test_execution.py @@ -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"), [