Skip to content

Commit

Permalink
explicit set of pythonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
smythi93 committed Jul 25, 2024
1 parent 71774ad commit 9956400
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
24 changes: 14 additions & 10 deletions src/sflkit/runners/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ class VoidRunner(Runner):


class PytestRunner(Runner):
def __init__(
self,
re_filter: str = r".*",
timeout=DEFAULT_TIMEOUT,
set_python_path: bool = False,
):
super().__init__(re_filter, timeout)
self.set_python_path = set_python_path

@staticmethod
def _common_base(directory: Path, tests: List[str]) -> Path:
parts = directory.parts
Expand Down Expand Up @@ -182,10 +191,11 @@ def get_tests(
).absolute()
environ = dict(environ or os.environ)
environ["SFLKIT_PYTEST_COLLECTION_FINISH_FILE"] = str(tmp)
if "PYTHONPATH" in environ:
environ["PYTHONPATH"] = str(directory) + ":" + environ["PYTHONPATH"]
else:
environ["PYTHONPATH"] = str(directory)
if self.set_python_path:
if "PYTHONPATH" in environ:
environ["PYTHONPATH"] = str(directory) + ":" + environ["PYTHONPATH"]
else:
environ["PYTHONPATH"] = str(directory)
process = subprocess.run(
[
"python3",
Expand All @@ -199,12 +209,6 @@ def get_tests(
cwd=directory,
)
LOGGER.info(f"pytest collection finished with {process.returncode}")
LOGGER.info(f"stdout: {process.stdout}")
LOGGER.info(f"stderr: {process.stderr}")
if process.returncode != 0:
raise subprocess.CalledProcessError(
process.returncode, process.args, process.stdout, process.stderr
)
if not tmp.exists():
tmp = directory / "tmp_sflkit_pytest"
if tmp.exists():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_runner(self):
exclude="tests",
)
instrument_config(config)
runner = PytestRunner()
runner = PytestRunner(set_python_path=True)
output = Path(BaseTest.TEST_DIR, "events").absolute()
runner.run(
Path(BaseTest.TEST_DIR), output, files=[Path("tests", "test_middle.py")]
Expand Down

0 comments on commit 9956400

Please sign in to comment.