Skip to content

Commit cec4bf0

Browse files
authored
Retry upon test failure if in Windows (#468)
1 parent 0f781a5 commit cec4bf0

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

src/julia/tests/test_core.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from julia import JuliaError
1212
from julia.core import jl_name, py_name
1313

14+
from .utils import retry_failing_if_windows
15+
1416
python_version = sys.version_info
1517

1618

@@ -155,6 +157,11 @@ def test_module_dir(julia):
155157
@pytest.mark.pyjulia__using_default_setup
156158
@pytest.mark.julia
157159
def test_import_without_setup():
160+
check_import_without_setup()
161+
162+
163+
@retry_failing_if_windows
164+
def check_import_without_setup():
158165
command = [sys.executable, "-c", "from julia import Base"]
159166
print("Executing:", *command)
160167
subprocess.check_call(command)

src/julia/tests/test_libjulia.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from julia.core import JuliaInfo
4+
from julia.tests.utils import retry_failing_if_windows
45

56
from .test_compatible_exe import runcode
67

@@ -10,6 +11,11 @@
1011
@pytest.mark.skipif("juliainfo.version_info < (0, 7)")
1112
@pytest.mark.julia
1213
def test_compiled_modules_no():
14+
check_compiled_modules_no()
15+
16+
17+
@retry_failing_if_windows
18+
def check_compiled_modules_no():
1319
runcode(
1420
"""
1521
from julia.core import Julia

src/julia/tests/test_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from julia.core import UnsupportedPythonError
1010

1111
from .test_compatible_exe import runcode
12+
from .utils import _retry_on_failure, retry_failing_if_windows
1213

1314
try:
1415
from types import SimpleNamespace
@@ -35,9 +36,25 @@ def test_unsupported_python_error_dynamically_linked():
3536
assert "have to match exactly" in str(err)
3637

3738

39+
def test_retry_on_failure():
40+
c = [0]
41+
42+
def f():
43+
c[0] += 1
44+
assert c[0] >= 2
45+
46+
_retry_on_failure(f)
47+
assert c[0] == 2
48+
49+
3850
@pytest.mark.pyjulia__using_default_setup
3951
@pytest.mark.julia
4052
def test_atexit():
53+
check_atexit()
54+
55+
56+
@retry_failing_if_windows
57+
def check_atexit():
4158
proc = runcode(
4259
'''
4360
import os

src/julia/tests/utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
from __future__ import print_function
2+
13
import os
24
import sys
5+
import traceback
6+
from functools import wraps
37

48
import pytest
59

@@ -30,3 +34,33 @@
3034
"""
3135
Tests that are known to fail in Windows in GitHub Actions.
3236
"""
37+
38+
39+
def _retry_on_failure(*fargs, **kwargs):
40+
f = fargs[0]
41+
args = fargs[1:]
42+
for i in range(10):
43+
try:
44+
return f(*args, **kwargs)
45+
except Exception:
46+
print()
47+
print("{}-th try of {} failed".format(i, f))
48+
traceback.print_exc()
49+
return f(*args, **kwargs)
50+
51+
52+
def retry_failing_if_windows(test):
53+
"""
54+
Retry upon test failure if in Windows.
55+
56+
This is an ugly workaround for occasional STATUS_ACCESS_VIOLATION failures
57+
in Windows: https://github.com/JuliaPy/pyjulia/issues/462
58+
"""
59+
if not is_windows:
60+
return test
61+
62+
@wraps(test)
63+
def repeater(*args, **kwargs):
64+
_retry_on_failure(test, *args, **kwargs)
65+
66+
return repeater

0 commit comments

Comments
 (0)