Last active
October 25, 2019 02:44
-
-
Save marekyggdrasil/e65ee881c64d55dd247fed1363f9b569 to your computer and use it in GitHub Desktop.
Creating step-based tests in Python with alternative execution paths. In this example we want to perform a test which always starts with `step_a` and always ends with `step_d` but in the middle can take either `step_b` and `step_c` either alternative steps. We test if final number is `12` and it can be obtained as `3*4=12` or `2*6=12` and those …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python -m pytest run.py -vvv | |
============================= test session starts ============================== | |
platform darwin -- Python 3.5.3, pytest-4.2.0, py-1.8.0, pluggy-0.12.0 -- /Users/marek/.pyenv/versions/3.5.3/bin/python | |
cachedir: .pytest_cache | |
rootdir: /Users/marek/Development/qtl/36a5d4cb5674e14792b03b4f79b89402, inifile: | |
plugins: steps-1.6.4, timeout-1.3.3, flaky-3.6.1 | |
collected 8 items | |
braids_test.py::test_scenario_1[step_a] PASSED [ 12%] | |
braids_test.py::test_scenario_1[step_b] PASSED [ 25%] | |
braids_test.py::test_scenario_1[step_c] PASSED [ 37%] | |
braids_test.py::test_scenario_1[step_d] PASSED [ 50%] | |
braids_test.py::test_scenario_2[step_a] PASSED [ 62%] | |
braids_test.py::test_scenario_2[step_b_alt] PASSED [ 75%] | |
braids_test.py::test_scenario_2[step_c_alt] PASSED [ 87%] | |
braids_test.py::test_scenario_2[step_d] PASSED [100%] | |
=========================== 8 passed in 0.08 seconds =========================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from pytest_steps import test_steps | |
def step_a(steps_data): | |
steps_data.a = 12 | |
def step_b(steps_data): | |
steps_data.b = 4 | |
def step_b_alt(steps_data): | |
steps_data.b = 2 | |
def step_c(steps_data): | |
steps_data.c = 3 | |
def step_c_alt(steps_data): | |
steps_data.c = 6 | |
def step_d(steps_data): | |
assert steps_data.b*steps_data.c == steps_data.a | |
@test_steps(step_a, step_b, step_c, step_d) | |
def test_scenario_1(test_step, steps_data): | |
test_step(steps_data) | |
@test_steps(step_a, step_b_alt, step_c_alt, step_d, steps_data_holder_name='steps_data_alt') | |
def test_scenario_2(test_step, steps_data_alt): | |
test_step(steps_data_alt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment