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.
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.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ward-0.2.0a0.tar.gz.
File metadata
- Download URL: ward-0.2.0a0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
997eaad825bda022cd44d7ec607ca2e6c62f4851b13d8709389c36c9cc871081
|
|
| MD5 |
147b791481ffd91dc39b5d0bf2b4dad0
|
|
| BLAKE2b-256 |
e3d9c0ca7e8c6a83a5b3308ba9475b177fe60b4cd99efebf215aeff0355fd718
|
File details
Details for the file ward-0.2.0a0-py3-none-any.whl.
File metadata
- Download URL: ward-0.2.0a0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc8c31406973512398a44347b8a1ce120ea72a3d41c48cbbad1aced413ba71f2
|
|
| MD5 |
7b9e40dd51d0483ff7733706a343e1a5
|
|
| BLAKE2b-256 |
4162c047f865a572e540b0e0d2248305fcb27156535cbe685ef0f248cc27adbc
|