-
-
Notifications
You must be signed in to change notification settings - Fork 18
fix testrunner to handle relative entries in sys.path #1205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import platform | ||
import shutil | ||
import subprocess | ||
import sys | ||
|
||
import pytest | ||
|
@@ -263,6 +265,30 @@ def test_fixtures_with_errors( | |
result.assert_outcomes(passed=passes, failed=failures, errors=errors) | ||
|
||
|
||
def test_basilisp_test_noargs(pytester: pytest.Pytester): | ||
runtime.Namespace.remove(sym.symbol("a.test-path")) | ||
|
||
code = """ | ||
(ns tests.test-path | ||
(:require | ||
[basilisp.test :refer [deftest is]])) | ||
(deftest passing-test | ||
(is true)) | ||
""" | ||
pytester.makefile(".lpy", **{"./tests/test_path": code}) | ||
|
||
# I couldn't find a way to directly manipulate the pytester's | ||
# `sys.path` with the precise control needed by this test, so we're | ||
# invoking `basilisp test` directly as a subprocess instead ... | ||
basilisp = shutil.which("basilisp") | ||
cmd = [basilisp, "test"] | ||
result = subprocess.run(cmd, capture_output=True, text=True, cwd=pytester.path) | ||
Comment on lines
+280
to
+285
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it not use the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, there's no way to replicate the desired behavior exactly. We need a test case where sys.path starts with |
||
|
||
assert "==== 1 passed" in result.stdout.strip() | ||
|
||
assert result.returncode == 0 | ||
|
||
|
||
def test_ns_in_syspath(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch): | ||
runtime.Namespace.remove(sym.symbol("a.test-path")) | ||
|
||
|
@@ -324,11 +350,18 @@ def test_ns_not_in_syspath(pytester: pytest.Pytester): | |
(:require | ||
[basilisp.test :refer [deftest is]])) | ||
""" | ||
pytester.makefile(".lpy", **{"./test/a/test_path": code}) | ||
# In this test, we use a `testabc` directory instead of `test`, as | ||
# the latter can cause issues on macOS. Specifically, macOS has a | ||
# `/Library/Frameworks/Python.framework/Versions/3.xx/lib/python3.13/test` | ||
# directory is picked up, resulting in a slightly different error | ||
# message. | ||
pytester.makefile(".lpy", **{"./testabc/a/test_path": code}) | ||
pytester.syspathinsert() | ||
result: pytest.RunResult = pytester.runpytest("test") | ||
result: pytest.RunResult = pytester.runpytest("testabc") | ||
assert result.ret != 0 | ||
result.stdout.fnmatch_lines(["*ModuleNotFoundError: No module named 'test.a'"]) | ||
result.stdout.fnmatch_lines( | ||
["*ModuleNotFoundError: Module named 'a.test-path' is not in sys.path"] | ||
) | ||
|
||
|
||
def test_ns_with_underscore(pytester: pytest.Pytester): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this cause problems with the changes introduced by #1176 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and in particular it was breaking the
test_ns_not_in_syspath
test.Consider the following file relative to the project directory:
./test/a/test_path.lpy
, declared with the namespacea.test-path
.Running basilisp test will locate and load
a.test-path
due to""
in sys.path, but this is inconsistent because the namespace doesn't match the load path (it’s nottest.a.test-path
). Thus, an exception is thrown in this case.(To make this work, the user must add the
-p test
option to the cli tool)