GitHub logo
184 stars, 12 forks

Tips & tricks

Tagging tests

Use the free-form nature of test descriptions to your advantage. Put tags in your test descriptions to make it easy to select and run a specific subset of tests.

For example, you could mark tests with performance issues as "slow":

@test("[slow] fetch the entire transaction log")
def _(client=client):
log = client.fetch_entire_log()
assert log == [6, 2, 3, 1, 50]

Now you can run all tests that have been tagged as such:

ward --search "[slow]"

Another useful pattern is tagging tests with the name of the function or method they're testing so that you can easily run all tests that test a specific method. For example "run all tests where the method under test is MyCounter.increment":

@test("[MyCounter.increment] works for negative integers")
def _():
m = MyCounter(initial=-1)
assert m.increment() == 0
@test("[MyCounter.increment] works for positive integers")
def _():
m = MyCounter(initial=1)
assert m.increment() == 2

Now if we wished to run only tests that probe the MyCounter.increment method, we can run the following command:

ward --search "[MyCounter.increment]"