Skip to content

Commit f208d37

Browse files
committed
Attempt to fix tests from any directory
1 parent f2f855a commit f208d37

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

test/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66
"""Test configuration."""
77

8+
import os
89
import sys
910

1011
import pytest
1112

1213

14+
@pytest.fixture(autouse=True, scope="session")
15+
def add_cwd_to_syspath():
16+
"""Ensure the current working directory is in sys.path.
17+
18+
CFFI and ffcx.main compile/generate files into CWD by default. Without
19+
this, importlib.import_module cannot find those files when pytest is invoked
20+
from a directory that is not already on sys.path (e.g. the project root
21+
rather than the test/ subdirectory).
22+
"""
23+
cwd = os.getcwd()
24+
if cwd not in sys.path:
25+
sys.path.insert(0, cwd)
26+
27+
1328
@pytest.fixture(scope="module")
1429
def compile_args():
1530
"""Compiler arguments."""

0 commit comments

Comments
 (0)