I'm trying to test a hy project with pytest but am having trouble with pytest discovering my tests. What needs to be done so that pytest can pick up tests written in hy? I've made the assumption that tests can be written in hy and discovered by pytest because of the native_tests
section in the main hy repo. If this is a bad assumption, no need to read on. Please let me know.
My project root looks something like this:
src
.hy program files
tests
__init__.py
test_*.hy test files where each test function is prefixed with test-*
pytest.ini
inside of pytest.ini I have the following:
[pytest]
python_functions = test_* is_test_* hyx_test_* hyx_is_test_*
testpaths = tests
I stole the python_functions section out of the hy repo's setup.cfg
Thank you!
The missing ingredient is Hy's confest.py
, which defines hook functions pytest uses to discover tests. See the Hy wiki page for tips on using pytest that should be kept up to date as pytest (and Hy) change. Right now, Hyrule's conftest.py
looks like
import hy
# For the side-effect of allowing import of Hy programs.
import pytest
def pytest_collect_file(file_path, parent):
if file_path.name.startswith('test_') and file_path.suffix == '.hy':
return pytest.Module.from_parent(parent, path = file_path)