diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index 6798f8fe..0a0446ca 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -95,7 +95,11 @@ jobs: env: CIBW_BUILD: ${{ matrix.python }}*64 CIBW_TEST_EXTRAS: dev - CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }} + # Added a sleep command afterwards to let all cleanup finish; sometimes + # cibuildwheel reports it cannot clean up the temp dir used for testing, + # and fails the build. Sleeping seems to give pytest enough time to + # fully clean up. + CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }} && sleep 2 # Run with faulthandler and -s in the hope we get a stack trace on seg fault on windows... CIBW_TEST_COMMAND_WINDOWS: python -X faulthandler -m pytest -s {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }} # Disable auditwheel as it isn't compatible with setuptools_dso approach diff --git a/tests/conftest.py b/tests/conftest.py index 5eb86769..a8f432f6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,9 +6,20 @@ import string import subprocess import sys +from packaging.version import Version from typing import Any import pytest +# It is necessary to ensure we always import cothread.catools before aioca as +# doing this import will cause an EPICS context to be created, and it will also +# register an atexit function to delete it. +# If we were to import aioca first it would create an EPICS context, note it has +# created it, then try to delete it in its own atexit function which will +# collide with cothread's attempts to do the same (despite the fact in this +# configuration cothread did not create the context) +if os.name != "nt": + import cothread.catools + from softioc import builder from softioc.builder import ClearRecords, SetDeviceName, GetRecordNames @@ -73,12 +84,17 @@ def cothread_ioc(): def aioca_cleanup(): - from aioca import purge_channel_caches, _catools + from aioca import purge_channel_caches, _catools, __version__ # Unregister the aioca atexit handler as it conflicts with the one installed # by cothread. If we don't do this we get a seg fault. This is not a problem # in production as we won't mix aioca and cothread, but we do mix them in # the tests so need to do this. - atexit.unregister(_catools._Context._destroy_context) + # In aioca 1.8 the atexit function was changed to no longer cause this + # issue, when coupled with ensuring cothread is always imported first. + if Version(__version__) < Version("1.8"): + unregister_func = _catools._Context._destroy_context + atexit.unregister(unregister_func) + # purge the channels before the event loop goes purge_channel_caches()