Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: run tests from wheel or sdist

For a package I've authored, I've done python setup.py sdist bdist_wheel, which generates some package artifacts in the dist/ directory. Now I'd like to run the package's unit tests in those artifacts. What's a good way to do it?

To be clear: an alternative would be to run the tests directly from the local source files, but I want to avoid that to make sure I'm testing the exact pre-built artifact users would be installing (as suggested here).

I'm using Python 3, and I'm on a Linux or Mac OS environment. My context is a build server that builds, tests, and then publishes artifacts (to a private PyPI-like repo) as commits are made to a Git repository.

If there's some other approach I should be using instead, I'm all ears.

like image 714
Ken Williams Avatar asked Mar 23 '17 17:03

Ken Williams


1 Answers

What you can do is:

  • Create a virtual environment
  • Install your package
  • Run the tests against your installed library using tools like pytest, you can read more about pytest good practices here: http://pytest.org/dev/goodpractises.html

As pointed in the pytest docs take a look to tox as well for your CI server: http://pytest.org/dev/goodpractises.html#use-tox-and-continuous-integration-servers

This is a related question regarding how to test using the installed package: Force py.test to use installed version of module

like image 72
Enrique Saez Avatar answered Oct 18 '22 17:10

Enrique Saez