0

我正在尝试使用 pytest 测试一个 hy 项目,但在 pytest 发现我的测试时遇到了麻烦。需要做什么才能使 pytest 能够获取用 hy 编写的测试?我假设测试可以用 hy 编写并由 pytest 发现,因为native_tests主 hy repo 中的部分。如果这是一个错误的假设,则无需继续阅读。请告诉我。

我的项目根目录如下所示:

src
  .hy program files
tests
  __init__.py
  test_*.hy test files where each test function is prefixed with test-*
pytest.ini

在 pytest.ini 我有以下内容:

[pytest]
python_functions = test_* is_test_* hyx_test_* hyx_is_test_*
testpaths = tests

我从 hy repo 的 setup.cfg 中偷走了 python_functions 部分

谢谢!

4

1 回答 1

1

缺少的成分是 Hy's confest.py,它定义了 pytest 用来发现测试的钩子函数。例如,我们这样定义pytest_collect_file

def pytest_collect_file(parent, path):
    if (path.ext == ".hy"
        and NATIVE_TESTS in path.dirname + os.sep
        and path.basename != "__init__.hy"):

        if hasattr(pytest.Module, "from_parent"):
            pytest_mod = pytest.Module.from_parent(parent, fspath=path)
        else:
            pytest_mod = pytest.Module(path, parent)
        return pytest_mod
于 2020-07-03T15:38:08.940 回答