mardi 19 novembre 2019

Managing Virtual Environments for Testing Python Scripts

I am trying to run a test suite for a Python script that relies on other Python scripts to be running in order to be able to test everything properly. All of these scripts are production level and get deployed in their own virtual environments on our servers, so I want to replicate a similar configuration when testing them. Creating and managing the virtual environments manually is a pain, but I have found several tools like tox/nox that can do the job.

However, with these tools I can do something like:

nox -f my_tester.py -- -t test_suite_name -p test_prefix

where my_tester.py is a "runner" for these test suites. The arguments after the -- are passed along to the tester, so I can specify which test suites to run, etc. Then from within my_tester.py I can do things like session.install(-r, 'requirements.txt'), then session.run(...) for each other script that needs to be stared, and finally session.run('pytest', 'test_suite_name'), etc. within this single virtual environment.

What I want to do, is perhaps be able to call something like:

python -m pytest test_suite_name/

and then be able to manage the virtual environments for each app separately based on my own configuration. So if I know test_suite_name requires two other scripts to be running, I could do like build the virtual environment for script one, then start it within that environment, continue on to script two, etc. After digging through the source code for nox, it doesn't seem that this functionality is possible, at least in a public manner.

Are there other libraries or even built-in functionality that allow me to do what I want? Is there perhaps a better architectural way to do this testing in the first place?

Aucun commentaire:

Enregistrer un commentaire