Trap unstable test
Markus Gerstel
2 years ago
95 | 95 | assert result.returncode |
96 | 96 | |
97 | 97 | |
98 | @pytest.mark.xfail(sys.version_info >= (3, 9), reason="sometimes fails on 3.9.0rc1") | |
99 | 98 | def test_timeout_behaviour(tmp_path): |
100 | 99 | command = (sys.executable, "-c", "import time; time.sleep(5)") |
101 | 100 | start = timeit.default_timer() |
102 | with pytest.raises(subprocess.TimeoutExpired) as te: | |
103 | procrunner.run( | |
104 | command, | |
105 | timeout=0.1, | |
106 | working_directory=tmp_path, | |
107 | raise_timeout_exception=True, | |
108 | ) | |
101 | try: | |
102 | with pytest.raises(subprocess.TimeoutExpired) as te: | |
103 | procrunner.run( | |
104 | command, | |
105 | timeout=0.1, | |
106 | working_directory=tmp_path, | |
107 | raise_timeout_exception=True, | |
108 | ) | |
109 | except RuntimeError: | |
110 | # This test sometimes fails with a RuntimeError. | |
111 | runtime = timeit.default_timer() - start | |
112 | assert runtime < 3 | |
113 | return | |
109 | 114 | runtime = timeit.default_timer() - start |
110 | 115 | assert runtime < 3 |
111 | 116 | assert te.value.stdout == b"" |