Skip to content
Advertisement

running a package pytest with poetry

I am new to poetry and want to get it set-up with pytest. I have a package mylib in the following set-up

├── dist
│   ├── mylib-0.0.1-py3-none-any.whl
│   └── mylib-0.0.1.tar.gz
├── poetry.lock
├── mylib
│   ├── functions.py
│   ├── __init__.py
│   └── utils.py
├── pyproject.toml
├── README.md
└── tests
    └── test_functions.py

in test_functions I have

import mylib

However, when I run

poetry run pytest

it complains about mylib not being included. I can run

pip install dist/mylib-0.0.1-py3-none-any.whl

but that clutters my python environment with mylib. I want to use that environment as well for other packages.

My question is: What is the proper way to work with poetry and pytest?

My underlying python environment is a clean pyenv python 3.8. Using pyproject.toml I create a project based virtual environment for mylib.

Advertisement

Answer

You need to run poetry install to set up your dev environment. It will install all package and development requirements, and once that is done it will do a dev-install of your source code.

You only need to run it once, code changes will propagate directly and do not require running the install again.


If you have set up the virtual env that you want already, take care that it is activated when you run the install command. If you don’t, poetry will try to create a new virtual env and use that, which is probably not what you want.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement