From f208d376fbecb82ccdd66c4e553c98693b5b3e8b Mon Sep 17 00:00:00 2001 From: "Jack S. Hale" Date: Wed, 10 Jun 2026 15:56:19 +0200 Subject: [PATCH 1/3] Attempt to fix tests from any directory --- test/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/conftest.py b/test/conftest.py index 1092de329..b5eab0980 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -5,11 +5,26 @@ # SPDX-License-Identifier: LGPL-3.0-or-later """Test configuration.""" +import os import sys import pytest +@pytest.fixture(autouse=True, scope="session") +def add_cwd_to_syspath(): + """Ensure the current working directory is in sys.path. + + CFFI and ffcx.main compile/generate files into CWD by default. Without + this, importlib.import_module cannot find those files when pytest is invoked + from a directory that is not already on sys.path (e.g. the project root + rather than the test/ subdirectory). + """ + cwd = os.getcwd() + if cwd not in sys.path: + sys.path.insert(0, cwd) + + @pytest.fixture(scope="module") def compile_args(): """Compiler arguments.""" From 744dedbb90f59928d0791374a85ea4389ff2ab52 Mon Sep 17 00:00:00 2001 From: "Jack S. Hale" Date: Thu, 11 Jun 2026 09:13:43 +0200 Subject: [PATCH 2/3] Append, rather than insert - safer. --- test/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/conftest.py b/test/conftest.py index b5eab0980..228849ddc 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -22,7 +22,7 @@ def add_cwd_to_syspath(): """ cwd = os.getcwd() if cwd not in sys.path: - sys.path.insert(0, cwd) + sys.path.append(cwd) @pytest.fixture(scope="module") From b56da8df7891b3fde36a76ee221bcb589c2f2386 Mon Sep 17 00:00:00 2001 From: "Jack S. Hale" Date: Thu, 11 Jun 2026 09:49:48 +0200 Subject: [PATCH 3/3] Update conftest.py --- test/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 228849ddc..34d3dc35a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -16,9 +16,9 @@ def add_cwd_to_syspath(): """Ensure the current working directory is in sys.path. CFFI and ffcx.main compile/generate files into CWD by default. Without - this, importlib.import_module cannot find those files when pytest is invoked - from a directory that is not already on sys.path (e.g. the project root - rather than the test/ subdirectory). + this, importlib.import_module cannot find those files when ``pytest`` + is invoked from a directory that is not already on sys.path + (e.g. the project root rather than the test/ subdirectory). """ cwd = os.getcwd() if cwd not in sys.path: