Tests Demo: Package demonstrating how to use tox to test across multiple Python versions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Charles Reid baba1df7d9
update readme
2 years ago
docs/img add img to readme, and add shields 2 years ago
src add init version of adam sandler 2 years ago
tests add init version of adam sandler 2 years ago
.gitignore add pyenv file back 2 years ago
.python-version include pypy3.9 2 years ago
MANIFEST.in include all req files in manifest 2 years ago
Makefile add makefile and update instructions with quick start 2 years ago
Readme.md update readme 2 years ago
common.mk add makefile and update instructions with quick start 2 years ago
requirements-dev.txt update with info about environments 2 years ago
requirements.txt add init version of adam sandler 2 years ago
setup.py more updates and fixes for wheel tests 2 years ago
tox.ini expand to 3.7 2 years ago

Readme.md

adam-sandler

version-0.1.0

tests-unittesttests-pytesttests-tox

python-3.7-3.8-3.9-pypy3.9

Adam Sandler as Happy Gilmore

Package demonstrating how to run Python package tests via tox, covering multiple versions of Python.

Extremely Quick Start

The fastest way to get started is to set up a virtual environment, and install tox into it:

python -m virtualenv -p py39 vp && source vp/bin/activate

pip install tox

Now list all available tox environments:

tox -la

Build the package:

make build

Use this one make command to run all the tox tests:

make tox

(This will require some additional setup to have multiple correct versions of Python, see pyenv instructions below.)

Using tox

To use tox to run tests, start by installing the dev dependencies:

pip install -r requirements-dev.txt

Now you can list all of the available tox environments:

$ tox -l -v

default environments:
py39-sdist-test   -> Install as source distribution & test
py39-wheel-test   -> Install as binary wheel distribution & test
py38-sdist-test   -> Install as source distribution & test
py38-wheel-test   -> Install as binary wheel distribution & test
py37-sdist-test   -> Install as source distribution & test
py37-wheel-test   -> Install as binary wheel distribution & test
pypy39-sdist-test -> Install as source distribution & test
build             -> Create a source and wheel distribution. Creates .tar.gz and .whl artifacts in the dist folder.

See the next section for notes on how to use multiple python versions with pyenv.

To run an environment, use tox -e <env_name>, for example:

tox -e py39-sdist-test

The sdist-test environments will:

  • create a source distribution (.tar.gz file) for the package
  • install the package from that .tar.gz source distribution into the temporary tox virtual environment
  • run tests with pytest

The wheel-test environment will:

  • create a binary wheel distribution (.whl file) for the package
  • install the package from that wheel into the temporary tox virtual environment
  • run tests with pytest

Using tox with pyenv

Pyenv is a utility for installing and switching between multiple Python versions. It can be used to provide different Python versions to tox, so that the package can be tested against different Python versions.

Start by checking which versions of Python are installed via pyenv:

$ pyenv versions

  3.7.13
* 3.8.13
  3.9.13
  pypy3.9-7.3.9

In this example, there are multilpe versions of python installed and available via pyenv, with the global version being set to 3.8.13.

To make multiple versions of Python available to use, use the pyenv local command to activate different versions locally:

$ pyenv local 3.7.13 3.8.13 3.9.13 pypy3.9-7.3.9

$ pyenv versions

* 3.7.13 (set by /path/to/adam-sandler/.python-version)
* 3.8.13 (set by /path/to/adam-sandler/.python-version)
* 3.9.13 (set by /path/to/adam-sandler/.python-version)
* pypy3.9-7.3.9 (set by /path/to/adam-sandler/.python-version)

This will create a .python-local file.

Now when you run tox with no arguments, it runs all environments, and should be able to find each different version of python specified:

$ tox

...

___________________________________________ summary ____________________________________________
  py39-sdist-test: commands succeeded
  py39-wheel-test: commands succeeded
  py38-sdist-test: commands succeeded
  py38-wheel-test: commands succeeded
  py37-sdist-test: commands succeeded
  py37-wheel-test: commands succeeded
  pypy39-sdist-test: commands succeeded
  build: commands succeeded
  congratulations :)