Testing with Python

Installation

Several Python versions are already preinstalled:

Quick start

Add an appveyor.yml file to your repository root:

# appveyor.yml
---
environment:
  matrix:
  - TOXENV: py27
  - TOXENV: py35
  - TOXENV: py36
  - TOXENV: py37

build: off

install:
- pip install tox

test_script:
- tox

Test setup

A popular approach in the Python community for test setups and automation is to use Tox. This has a number of advantages:

  • It is self-contained, allowing you to encapsulate all dependencies for running your tests.
  • You can run the entire test suite on your developer machine upfront, with a single command.
  • It creates isolated environments for running your tests using virtualenv, automatically.
  • It makes you independent from implementation details of any CI service.

With the AppVeyor configuration from above you can now put your entire test setup into a tox.ini file in your repository root:

# tox.ini

[tox]
envlist = py{27,35,36,37}

[testenv]
description = Unit tests
deps = pytest
commands = pytest

For any Tox environment you want to run on AppVeyor you need to add a TOXENV: ... item to your environment matrix in appveyor.yml.

See usage examples and configuration specs for more information on how to use Tox.

Testing against PyPy

PyPy and PyPy3 are not yet supported on AppVeyor out-of-the-box. You can, however, install them yourself as additional interpreters in your appveyor.yml.

See the “How do I install PyPy on AppVeyor” question on StackOverflow for a possible strategy.

Note about dependency management

Since pipenv prints some statements to stderr, you should to silence it if it is the dependency manager you are using.

# appveyor.yml
...
  - ps: python -Wignore -m pip install pipenv
  - ps: rm Pipfile.lock
  - ps: $PIPENV_QUIET="true"
  - pipenv run conditional_install
Did you know that you can edit this page on GitHub and send us a Pull Request?