CARVIEW |
Run pytest against a specific Python version using Docker
For datasette issue #1802 I needed to run my pytest
test suite using a specific version of Python 3.7.
I decided to do this using Docker, using the official python:3.7-buster image.
Here's the recipe that worked for me:
docker run --rm -it -v `pwd`:/code \
python:3.7-buster \
bash -c "cd /code && pip install -e '.[test]' && pytest"
This command runs interactively so I can see the output (the -it
option).
It mounts the current directory (with my testable application in it - I ran this in the root of a datasette
checkout) as the /code
volume inside the container.
The --rm
option ensures that the container used for the test will be deleted once the test has completed (not just stopped).
It then runs the following using bash -c
:
cd /code && pip install -e '.[test]' && pytest
This installs my project's dependencies and test dependencies and then runs pytest
.
The truncated output looks like this:
% docker run -it -v `pwd`:/code \
python:3.7-buster \
bash -c "cd /code && pip install -e '.[test]' && pytest"
Obtaining file:///code
Preparing metadata (setup.py) ... done
Collecting asgiref>=3.2.10
Downloading asgiref-3.5.2-py3-none-any.whl (22 kB)
...
Installing collected packages: rfc3986, mypy-extensions, iniconfig, zipp, typing-extensions, typed-ast, tomli, soupsieve, sniffio, six, PyYAML, pyparsing, pycparser, py, platformdirs, pathspec, mergedeep, MarkupSafe, itsdangerous, idna, hupper, h11, execnet, cogapp, certifi, attrs, aiofiles, python-multipart, packaging, Jinja2, janus, importlib-metadata, cffi, beautifulsoup4, asgiref, anyio, pluggy, pint, httpcore, cryptography, click, asgi-csrf, uvicorn, trustme, pytest, httpx, click-default-group-wheel, black, pytest-timeout, pytest-forked, pytest-asyncio, datasette, blacken-docs, pytest-xdist
Running setup.py develop for datasette
...
========================================================= test session starts ==========================================================
platform linux -- Python 3.7.13, pytest-7.1.3, pluggy-1.0.0
SQLite: 3.27.2
rootdir: /code, configfile: pytest.ini
plugins: asyncio-0.19.0, anyio-3.6.1, timeout-2.1.0, xdist-2.5.0, forked-1.4.0
asyncio: mode=strict
collected 1054 items
tests/test_package.py .. [ 0%]
tests/test_cli.py . [ 0%]
tests/test_cli_serve_get.py .. [ 0%]
tests/test_cli.py . [ 0%]
tests/test_black.py . [ 0%]
tests/test_api.py .................................................. [ 5%]
Related
- docker Installing packages from Debian unstable in a Docker image based on stable - 2021-03-22
- python Quickly testing code in a different Python version using pyenv - 2023-07-10
- github-actions Talking to a PostgreSQL service container from inside a Docker container - 2020-09-18
- github-actions Running tests against multiple versions of a Python dependency in GitHub Actions - 2023-09-15
- docker Running gdb against a Python process in a running Docker container - 2021-03-21
- sqlite Using LD_PRELOAD to run any version of SQLite with Python - 2020-06-17
- pytest Using pytest and Playwright to test a JavaScript web application - 2022-07-24
- github-actions Running tests against PostgreSQL in a service container - 2021-02-23
- docker Using pipenv and Docker - 2022-11-28
- docker Testing things in Fedora using Docker - 2022-07-27
Created 2022-09-05T16:23:06-07:00, updated 2022-09-06T10:51:25-07:00 · History · Edit