Skip to content

Commit

Permalink
Retry upon test failure if in Windows (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf authored Oct 25, 2021
1 parent 0f781a5 commit cec4bf0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/julia/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from julia import JuliaError
from julia.core import jl_name, py_name

from .utils import retry_failing_if_windows

python_version = sys.version_info


Expand Down Expand Up @@ -155,6 +157,11 @@ def test_module_dir(julia):
@pytest.mark.pyjulia__using_default_setup
@pytest.mark.julia
def test_import_without_setup():
check_import_without_setup()


@retry_failing_if_windows
def check_import_without_setup():
command = [sys.executable, "-c", "from julia import Base"]
print("Executing:", *command)
subprocess.check_call(command)
Expand Down
6 changes: 6 additions & 0 deletions src/julia/tests/test_libjulia.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from julia.core import JuliaInfo
from julia.tests.utils import retry_failing_if_windows

from .test_compatible_exe import runcode

Expand All @@ -10,6 +11,11 @@
@pytest.mark.skipif("juliainfo.version_info < (0, 7)")
@pytest.mark.julia
def test_compiled_modules_no():
check_compiled_modules_no()


@retry_failing_if_windows
def check_compiled_modules_no():
runcode(
"""
from julia.core import Julia
Expand Down
17 changes: 17 additions & 0 deletions src/julia/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from julia.core import UnsupportedPythonError

from .test_compatible_exe import runcode
from .utils import _retry_on_failure, retry_failing_if_windows

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


def test_retry_on_failure():
c = [0]

def f():
c[0] += 1
assert c[0] >= 2

_retry_on_failure(f)
assert c[0] == 2


@pytest.mark.pyjulia__using_default_setup
@pytest.mark.julia
def test_atexit():
check_atexit()


@retry_failing_if_windows
def check_atexit():
proc = runcode(
'''
import os
Expand Down
34 changes: 34 additions & 0 deletions src/julia/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import print_function

import os
import sys
import traceback
from functools import wraps

import pytest

Expand Down Expand Up @@ -30,3 +34,33 @@
"""
Tests that are known to fail in Windows in GitHub Actions.
"""


def _retry_on_failure(*fargs, **kwargs):
f = fargs[0]
args = fargs[1:]
for i in range(10):
try:
return f(*args, **kwargs)
except Exception:
print()
print("{}-th try of {} failed".format(i, f))
traceback.print_exc()
return f(*args, **kwargs)


def retry_failing_if_windows(test):
"""
Retry upon test failure if in Windows.
This is an ugly workaround for occasional STATUS_ACCESS_VIOLATION failures
in Windows: https://github.com/JuliaPy/pyjulia/issues/462
"""
if not is_windows:
return test

@wraps(test)
def repeater(*args, **kwargs):
_retry_on_failure(test, *args, **kwargs)

return repeater

0 comments on commit cec4bf0

Please sign in to comment.