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

前端 未结 20 2814
孤独总比滥情好
孤独总比滥情好 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:28

    I was having the same problem when following the Flask tutorial and I found the answer on the official Pytest docs It's a little shift from the way I (and I think many others) are used to do things.

    You have to create a setup.py file in your project's root directory with at least the following two lines:

    from setuptools import setup, find_packages
    setup(name="PACKAGENAME", packages=find_packages())
    

    where PACKAGENAME is your app's name. Then you have to install it with pip:

    pip install -e .
    

    The -e flag tells pip to intall the package in editable or "develop" mode. So the next time you run pytest it should find your app in the standard PYTHONPATH.

提交回复
热议问题