[pytest-dev] What is the best practice for tests that install python packages and run their tests?
davide.moro at gmail.com
Sat Jun 23 01:47:26 EDT 2018
I think you could run safely things using docker. With docker no need to
install a virtual env (use the simply the system python). You have to
provide on the fly an image with preinstalled what you need starting with a
Dockerfile and a requirements.txt (with all versions pinned) with a pytest
ENTRYPOINT I suppose. You can use a pytest fixture where you build a docker
image and later you can docker run it providing the CMD argument in command
line. You can also parameterize the fixture and repeating your tests
against any operative system (Ubuntu, fedora, alpine, Suse, etc) from any
host. Remember the rm option running the image.
Alternatively it is fine too a virtual environment in a temp directory but
you have to preinstalled what you need, using a requirements.txt file. If
there is a bug in your testware be aware because there might be the risk of
the outer python environment pollution.
Hope it helped.
On Thu, 21 Jun 2018, 11:35 Vasily Kuznetsov, <kvas.it at gmail.com> wrote:
> Hello, everyone!
> Some time ago I wrote a pytest plugin  that helps with testing of
> scripts declared by 'console_scripts' entry point in setup.py. The tests of
> this plugin install a test package (let's call it TP) and then run TP's
> tests that are verifying that the scripts declared by TP's setup.py work as
> expected. TP is installed into the same python environment that runs the
> outer tests (uninstalled at fixture cleanup) and then the inner tests are
> run with the same pytest instance that runs the outer tests. This approach
> is somewhat dirty, but it works fine with disposable virtualenvs that we
> get from Tox.
> In the process of trying to package this plugin for Fedora it turned out
> that my test approach doesn't work with the way they run tests. They use
> system python so my tests try to install things into system python, don't
> have permissions and fail (see ).
> I think this could be fixed by creating a virtualenv in tmpdir and using
> that to install TP and run its tests. However, this new virtualenv would
> need to have pytest and pytest-console-scripts installed in it in order to
> run the inner tests. I'm planning to look into the ways to make a
> virtualenv inherit packages from another virtualenv (or from system python,
> as would be the case with Fedora package testing) but before I go into all
> this, I thought I would ask around if maybe there's a better way.
> Have any of you had situations where your tests needed to install packages
> and run their tests and how did you go about this?
> : https://pypi.org/project/pytest-console-scripts/
> : https://github.com/kvas-it/pytest-console-scripts/issues/11
> pytest-dev mailing list
> pytest-dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pytest-dev