diff --git a/changelog.d/+macos-testsuite-fixes.fixed.md b/changelog.d/+macos-testsuite-fixes.fixed.md new file mode 100644 index 0000000000..e6c9fae6ad --- /dev/null +++ b/changelog.d/+macos-testsuite-fixes.fixed.md @@ -0,0 +1 @@ +Make the test suite easier to run under MacOS \ No newline at end of file diff --git a/python/nav/Snmp/__init__.py b/python/nav/Snmp/__init__.py index 41fa44e845..572d777f17 100644 --- a/python/nav/Snmp/__init__.py +++ b/python/nav/Snmp/__init__.py @@ -21,6 +21,8 @@ """ from __future__ import absolute_import +import os +import sys BACKEND = None @@ -35,6 +37,12 @@ # These wildcard imports are informed, not just accidents. # pylint: disable=W0401 if BACKEND == 'pynetsnmp': + if sys.platform == "darwin" and not os.getenv("DYLD_LIBRARY_PATH"): + # horrible workaround for MacOS problems, described at length at + # https://hynek.me/articles/macos-dyld-env/ + os.environ["DYLD_LIBRARY_PATH"] = os.getenv( + "LD_LIBRARY_PATH", "/usr/local/opt/openssl/lib" + ) from .pynetsnmp import * else: raise ImportError("No supported SNMP backend was found") diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 437d0278cc..a7ddecd539 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -2,6 +2,7 @@ import os import importlib.util import io +import platform import re import shlex from itertools import cycle @@ -41,10 +42,11 @@ def pytest_configure(config): bootstrap_django('pytest') - # Install custom reactor for Twisted tests - from nav.ipdevpoll.epollreactor2 import install + if platform.system() == 'Linux': + # Install custom reactor for Twisted tests + from nav.ipdevpoll.epollreactor2 import install - install() + install() # Setup test environment for Django from django.test.utils import setup_test_environment diff --git a/tox.ini b/tox.ini index edd85b533d..37c676541c 100644 --- a/tox.ini +++ b/tox.ini @@ -46,6 +46,7 @@ setenv = django32: DJANGO_VER=32 django40: DJANGO_VER=40 passenv = + C_INCLUDE_PATH GITHUB_ACTIONS GITHUB_RUN_ID USER @@ -56,6 +57,8 @@ passenv = PGPASSWORD WORKSPACE DISPLAY + DYLD_LIBRARY_PATH + LD_LIBRARY_PATH allowlist_externals = sh sed