Skip to content

Collecting tests from Python modules not generated by Python files #2369

@Kodiologist

Description

@Kodiologist

I'm a core developer of the Hy programming language, which is a Lisp syntax for Python, and I'm trying to migrate its test suite from Nose to pytest. The repository has a lot of tests written in Python but also tests written in Hy. Hy itself is implemented in Python and provides a meta-importer so that a Python program can import a Hy module just like a Python module. So in theory, pytest should be able to collect tests from Hy files just as well as Python files, so long as Hy's meta-importer is active. Once a Hy file is loaded, there's basically no difference between Hy and Python; a Hy module is in fact a Python module.

I found a hacky way to run the Hy tests, using this conftest.py, which calls _pytest.python.pytest_pycollect_makemodule in a pytest_collect_file hook. The catch is that this hits assert name.endswith(".py") in _pytest.python, and Hy files end with .hy, not .py. If the assertion is commented out, everything works.

Is there a better way to do this? If not, perhaps you should remove the assertion.

I'm using pytest 3.0.7. Hy is intended to support, and is tested on, Python 2.7 and Python 3.3 and up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: help wanteddevelopers would like help from experts on this topictopic: collectionrelated to the collection phasetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions