跳转到主要内容

基于Type-safe YAML的Python示例驱动开发框架。

项目描述

HitchStory

Main branch status

类型安全的StrictYAML Python集成测试框架。使用此框架,您的测试可以

从程序输出(命令行测试示例)中重新编写自己

Test rewriting itself

自动生成文档(网站测试示例)

Test writing docs

测试可以单独运行,也可以作为pytest测试运行。

包含示例测试的演示项目

项目 故事测试 Python代码 文档模板 自动生成的文档
网站 添加待办事项纠正拼写 engine.py docstory.yml 添加待办事项纠正我的拼写
REST API 添加待办事项纠正拼写 engine.py docstory.yml 添加待办事项纠正我的拼写
交互式命令行应用程序 添加待办事项纠正拼写 test_integration.py docstory.yml 添加待办事项纠正我的拼写
Python API 添加待办事项纠正拼写 test_integration.py docstory.yml 添加待办事项纠正我的拼写

代码示例

example.story

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


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

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

engine.py

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

class Engine(BaseEngine):
    given_definition = GivenDefinition(
        website=GivenProperty(Str()),
    )
    
    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!"
        try:
            strings_match(expected_message, actual_message)
        except Failure:
            if self._rewrite:
                self.current_step.rewrite("expected_message").to(actual_message)
            else:
                raise

    def email_was_sent(self):
        print("Check email was sent!")
>>> from hitchstory import StoryCollection
>>> from pathlib import Path
>>> from engine import Engine
>>> 
>>> StoryCollection(Path(".").glob("*.story"), Engine()).named("Email sent").play()
RUNNING Email sent in /path/to/working/example.story ... Load web page at /login
Put hunter2 in name
Put AzureDiamond in name
Click on login
Click on new email
Put Hey guys,

I think I got hacked!
 in name
Put Cthon98@aol.com in name
Click on send email
Check email was sent!
SUCCESS in 0.1 seconds.

安装

$ pip install hitchstory

社区

如果您在这些地方提出问题,可以获得帮助:GitHub 讨论区 | GitHub 问题(不仅限于错误)| Slack 频道

使用 HitchStory

本库的每个功能都有文档,并列在下面。它与其自身一起进行了测试和文档化。

使用 HitchStory:与 Pytest 一起使用

如果您已经设置了 pytest,则可以快速轻松地使用 hitchstory 编写一个测试,该测试可以与您的其他 pytest 测试一起运行

使用 HitchStory:引擎

如何使用故事引擎的不同功能

使用 HitchStory:文档生成

如何从您的测试中自动生成文档

使用 HitchStory:继承

相互继承故事

使用 HitchStory:运行器

以不同方式运行故事

使用 HitchStory 的方法

最佳实践,如何使用此工具,等等。

设计决策和原则

设计决策在这里得到证明

为什么不使用X?

HitchStory不是唯一的集成测试框架。这是它与其它框架的比较。

使用HitchStory:独立设置

如果你想在没有pytest的情况下使用HitchStory

使用HitchStory:行为

关于框架行为的杂项文档

项目详情


版本历史 发布通知 | RSS源

下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

hitchstory-0.24.0.tar.gz (33.0 kB 查看哈希值)

上传时间

构建分布

hitchstory-0.24.0-py3-none-any.whl (30.3 kB 查看哈希值)

上传时间 Python 3

支持者