Description
Hi,
There seems to be an issue when running Basilisp tests located in a subdirectory, where the test namespace does not include the root directory but the subdirectory is added to the sys.path
.
For example, a test file at test2/a/test2_test.lpy
with the namespace a.test2-test
should run when basilisp test is invoked with the correct --include-path
. However, the tests are not detected despite the file is loaded.
case 1
For example in the first example below where the namespace a.test2-test
does not start with the top test directory test2/
test2/a/test2_test.lpy
(ns a.test2-test
(:require [basilisp.test :refer [deftest is]]))
(deftest a-test2-test
(is (= 7 8)))
the tests are not detected even though I specified that the top subdirectory is in the sys.path
(so no need to start the namespace with it)
> basilisp test --include-path test2 test2
==== test session starts ===================================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issue-bas-test-startdir
configfile: pyproject.toml
plugins: basilisp-0.3.3
collected 0 items
case 2
In the second example below where I do place the top directory name in the namespace test1.a.test1-test
the tests are loaded as expected (failure here is intentional to prove the test was loaded and executed)
test1/a/test1_test.lpy
(ns test1.a.test1-test
(:require
[basilisp.test :refer [deftest is]]))
(deftest the-test1-test
(is (= 5 6)))
> basilisp test test1
==== test session starts ===================================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issue-bas-test-startdir
configfile: pyproject.toml
plugins: basilisp-0.3.3
collected 1 item
test1\a\test1_test.lpy F [100%]
==== FAILURES ========================================================================
_____ the-test1-test _____________________________________________________________________
FAIL in (the-test1-test) (test1_test.lpy:6)
Test failure: (= 5 6)
expected: 5
actual: 6
expectations
I expected that if I have tests in a subdirectory of the project, with test namespaces starting from that subdirectory (case 1), I should be able to run them by specifying basilisp test --include-path <subdirectory> <subdirectory>
. Am I perhaps missing something?
I’ve created a repository with the test cases mentioned: https://github.com/ikappaki/issue-bas-test-startdir, in case you'd like to have a look.
Thanks
Another strange behavior occurs if I add a println
statement at the top level of test2_test.lpy
as shown below It results in a name 'basilisp_core' is not defined
error, which I don’t fully understand where it is coming from:
(ns a.test2-test
(:require [basilisp.test :refer [deftest is]]))
(println :test2)
;; NameError: name 'basilisp_core' is not defined
(deftest a-test2-test
(is (= 7 8)))
> basilisp test --include-path test2 test2
==== test session starts ===================================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issue-bas-test-startdir
configfile: pyproject.toml
plugins: basilisp-0.3.3
collected 0 items / 1 error
========================================================================= ERRORS =========================================================================
________________________________________________________ ERROR collecting test2/a/test2_test.lpy _________________________________________________________
.venv\Lib\site-packages\basilisp\importer.py:408: in exec_module
self._exec_cached_module(fullname, spec.loader_state, path_stats, ns)
.venv\Lib\site-packages\basilisp\importer.py:313: in _exec_cached_module
cached_code = _get_basilisp_bytecode(
.venv\Lib\site-packages\basilisp\importer.py:78: in _get_basilisp_bytecode
raise ImportError(message, **exc_details)
E ImportError: Non-matching timestamp (1732907277) in test2.a.test2_test bytecode cache; expected 1732912476
During handling of the above exception, another exception occurred:
test2\a\test2_test.lpy:7: in <module>
(println :test2)
E NameError: name 'basilisp_core' is not defined