PATH issue with pytest 'ImportError: No module named YadaYadaYada'

前端 未结 20 2669
孤独总比滥情好
孤独总比滥情好 2020-11-22 07:10

I used easy_install to install pytest on a mac and started writing tests for a project with a file structure likes so:

repo/
repo/app.py
repo/settings.py
rep         


        
20条回答
  •  温柔的废话
    2020-11-22 07:44

    I created this as an answer to your question and my own confusion. I hope it helps. Pay attention to PYTHONPATH in both the py.test command line and in the tox.ini.

    https://github.com/jeffmacdonald/pytest_test

    Specifically: You have to tell py.test and tox where to find the modules you are including.

    With py.test you can do this:

    PYTHONPATH=. py.test
    

    And with tox, add this to your tox.ini:

    [testenv]
    deps= -r{toxinidir}/requirements.txt
    commands=py.test
    setenv =
        PYTHONPATH = {toxinidir}
    

提交回复
热议问题