Skip to content

This example demonstrates the stories in the README being run via a command line runner. It can be directly copied and pasted.

This is useful if you want to run the tests outside of pytest.

It uses the popular click package to interpret command line arguments.

Code Example


Logged in:
    website: /login  # preconditions
  - Form filled:
      username: AzureDiamond
      password: hunter2
  - Clicked: login

Email sent:
  about: |
    The most basic email with no subject, cc or bcc
  based on: logged in             # inherits from and continues from test above
  following steps:
  - Clicked: new email
  - Form filled:
      contents: |                # long form text
        Hey guys,

        I think I got hacked!
  - Clicked: send email
  - Email was sent

from hitchstory import BaseEngine, GivenDefinition, GivenProperty
from hitchstory import Failure, strings_match
from strictyaml import Str

class Engine(BaseEngine):
    given_definition = GivenDefinition(

    def __init__(self, rewrite=False):
        self._rewrite = rewrite

    def set_up(self):
        print(f"Load web page at {self.given['website']}")

    def form_filled(self, **textboxes):
        for name, contents in sorted(textboxes.items()):
            print(f"Put {contents} in name")

    def clicked(self, name):
        print(f"Click on {name}")

    def failing_step(self):
        raise Failure("This was not supposed to happen")

    def error_message_displayed(self, expected_message):
        """Demonstrates steps that can rewrite themselves."""
        actual_message = "error message!"
            strings_match(expected_message, actual_message)
        except Failure:
            if self._rewrite:

    def email_was_sent(self):
        print("Check email was sent!")

from hitchstory import StoryCollection
from click import argument, group, pass_context
from engine import Engine
from pathlib import Path

THIS_DIR = Path(__file__).absolute().parents[0]

STORIES = THIS_DIR.glob("*.story")

def cli(ctx):
    """Integration test command line interface."""

@argument("keywords", nargs=-1)
def atdd(keywords):
    Run single story with name matching keywords.
    StoryCollection(STORIES, Engine())\

@argument("keywords", nargs=-1)
def ratdd(keywords):
    Run single story with name matching keywords in rewrite mode.
    StoryCollection(STORIES, Engine())\

def regression():
    Run all tests.
    StoryCollection(STORIES, Engine())\

if __name__ == "__main__":

Regular ATDD

Run a single test.

Rewrite ATDD

Run a single test in rewrite mode.


Run all tests.

Executable specification

Documentation automatically generated from basic-cli.story storytests.