Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A Python 3 test framework.

Project description

Ward

An experimental test runner for Python 3.6+ that is heavily inspired by pytest. This project is a work in progress, and is not production ready.

screenshot

Examples

Dependency Injection

In the example below, we define a single fixture named cities. Our test takes a single parameter, which is also named cities. Ward sees that the fixture name and parameter names match, so it calls the cities fixture, and passes the result into the test.

from ward.fixtures import fixture

@fixture
def cities():
    return ["Glasgow", "Edinburgh"]

def test_using_cities(cities):
    assert cities == ["Glasgow", "Edinburgh"]

The Expect API

In the test_capital_cities test, we want to determine whether the get_capitals_from_server function is behaving as expected, so we grab the output of the function and pass it to expect. From here, we check that the response is as we expect it to be by chaining methods. If any of the checks fail, the expect chain short-circuits, and the remaining checks won't be executed for that test. Methods in the Expect API are named such that they correspond as closely to standard Python operators as possible, meaning there's not much to memorise.

from ward.fixtures import fixture
from ward.expect import expect

@fixture
def cities():
    return {"edinburgh": "scotland", "tokyo": "japan", "london": "england", "warsaw": "poland", "berlin": "germany",
            "madrid": "spain"}

def test_capital_cities(cities):
    found_cities = get_capitals_from_server()

    (expect(found_cities)
     .is_instance_of(dict)
     .contains("tokyo")
     .has_length(6)
     .equals(cities))

Checking for exceptions

The test below will pass, because a ZeroDivisionError is raised. If a ZeroDivisionError wasn't raised, the test would fail.

from ward.expect import raises

def test_expecting_an_exception():
    with raises(ZeroDivisionError):
        1/0

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ward, version 0.2.0a0
Filename, size File type Python version Upload date Hashes
Filename, size ward-0.2.0a0-py3-none-any.whl (12.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ward-0.2.0a0.tar.gz (8.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page