Running pytest with cython - how to compile cython modules in pytest?

前端 未结 1 723
余生分开走
余生分开走 2021-01-16 03:49

I have a project organized as follows:

project
├── project
│   ├── module1
│   │   ├── api.py
│   │   ├── _cpython_foo.py
│   │   └── _cython_foo.pyx
│   └──         


        
1条回答
  •  执念已碎
    2021-01-16 04:18

    I know about two ways of marrying pytest with cythonized extensions:

    1. Do not invoke the tests via pytest directly; instead, use in-place test command with the setup script. To do that, install pytest-runner plugin that adds a pytest command:

      $ pip install pytest-runner
      

      Now you should be able to invoke the tests with pytest by issuing

      $ python setup.py pytest
      

      This approach, however, will require some changes in the way the command line args are passed: the pendant to command

      $ pytest --arg1 --arg2
      

      will be

      $ python setup.py pytest --addopts "--arg1 --arg2"
      
    2. If you want to continue using the pytest command: install the project in development mode (ideally, in a virtualenv).

      (myenv) $ pip install --editable dir/
      

      where dir/ is the directory containing the setup.py script. Now the extensions will be prebuilt and pytest will be able to resolve them.

    0 讨论(0)
提交回复
热议问题