basilisp icon indicating copy to clipboard operation
basilisp copied to clipboard

Can't run tests in a new Basilisp project

Open ikappaki opened this issue 5 months ago • 8 comments

Hi,

it's not possible to execute Basilisp tests in a new project due to the following error

ERROR tests/issuetests/issue_test.lpy - ModuleNotFoundError: No module named 'tests'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

To reproduce with poetry

  1. Create a new issuetests project, add basilisp and pytest deps, and install project
PS D:\bas> poetry new --src issuetests
...
PS D:\bas> cd .\issuetests\
...
PS D:\bas\issuetests> poetry add basilisp
Creating virtualenv issuetests in D:\bas\issuetests\.venv
Using version ^0.2.3 for basilisp
...
PS D:\bas\issuetests> poetry add pytest --dev
The --dev option is deprecated, use the `--group dev` notation instead.
Using version ^8.3.3 for pytest
...
PS D:\bas\issuetests> poetry install
...
Installing the current project: issuetests (0.1.0)
  1. Create a test file with the following content ./tests/issuetests/issue_test.lpy
(ns tests.issuetests.issue-test
  (:require [basilisp.test :refer [deftest are is testing]]))

(deftest xyz []
  (is (= 5 5)))
  1. Run pytest, you will encounter the "No module named 'tests' error"
PS D:\bas\issuetests> poetry run pytest
================================================= test session starts =================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issuetests
configfile: pyproject.toml
plugins: basilisp-0.2.3
collected 0 items / 1 error

======================================================= ERRORS ========================================================
__________________________________ ERROR collecting tests/issuetests/issue_test.lpy ___________________________________
.venv\Lib\site-packages\basilisp\contrib\pytest\testrunner.py:234: in collect
    module = self._import_module()
.venv\Lib\site-packages\basilisp\contrib\pytest\testrunner.py:222: in _import_module
    module = importlib.import_module(modname)
C:\local\Python311\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1126: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:241: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1126: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:241: in _call_with_frames_removed
    ???
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1140: in _find_and_load_unlocked
    ???
E   ModuleNotFoundError: No module named 'tests'
=============================================== short test summary info ===============================================
ERROR tests/issuetests/issue_test.lpy - ModuleNotFoundError: No module named 'tests'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================== 1 error in 0.10s ===================================================

The same error occurs when running basilisp test.

A workaround I found to bypass this issue is to create an empty conftest.py file ./tests/conftest.py (Empty)

though this is not mentioned in the official documentation as a requirement https://basilisp.readthedocs.io/en/v0.1.1/gettingstarted.html#project-structure

PS D:\bas\issuetests> poetry run pytest
================================================= test session starts =================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issuetests
configfile: pyproject.toml
plugins: basilisp-0.2.3
collected 1 item

tests\issuetests\issue_test.lpy .                                                                                [100%]

================================================== 1 passed in 0.04s ==================================================

Running basilisp test gives an extra warning, but I this is unrelated to this issue

PS D:\bas\issuetests> poetry run basilisp test
================================================= test session starts =================================================
platform win32 -- Python 3.11.4, pytest-8.3.3, pluggy-1.5.0
rootdir: D:\bas\issuetests
configfile: pyproject.toml
plugins: basilisp-0.2.3
collected 1 item

tests\issuetests\issue_test.lpy .                                                                                [100%]

================================================== warnings summary ===================================================
.venv\Lib\site-packages\_pytest\config\__init__.py:1277
  D:\bas\issuetests\.venv\Lib\site-packages\_pytest\config\__init__.py:1277: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: basilisp
    self._mark_plugins_for_rewrite(hook)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================ 1 passed, 1 warning in 0.02s =============================================

Thanks

ikappaki avatar Sep 21 '24 10:09 ikappaki