Test if the code is generated by a given feature.
(pytester, monkeypatch, capsys)
| 10 | |
| 11 | |
| 12 | def test_generate(pytester, monkeypatch, capsys): |
| 13 | """Test if the code is generated by a given feature.""" |
| 14 | |
| 15 | features = pytester.mkdir("scripts") |
| 16 | feature = features.joinpath("generate.feature") |
| 17 | feature.write_text( |
| 18 | textwrap.dedent( |
| 19 | """\ |
| 20 | Feature: Code generation |
| 21 | |
| 22 | Scenario: Given and when using the same fixture should not evaluate it twice |
| 23 | Given I have an empty list |
| 24 | And 1 have a fixture (appends 1 to a list) in reuse syntax |
| 25 | |
| 26 | When I use this fixture |
| 27 | |
| 28 | Then my list should be [1] |
| 29 | """ |
| 30 | ), |
| 31 | "utf-8", |
| 32 | ) |
| 33 | |
| 34 | monkeypatch.setattr(sys, "argv", ["", "generate", str(feature)]) |
| 35 | main() |
| 36 | out, err = capsys.readouterr() |
| 37 | assert out == textwrap.dedent( |
| 38 | '''\ |
| 39 | """Code generation feature tests.""" |
| 40 | |
| 41 | from pytest_bdd import ( |
| 42 | given, |
| 43 | scenario, |
| 44 | then, |
| 45 | when, |
| 46 | ) |
| 47 | |
| 48 | |
| 49 | @scenario('scripts/generate.feature', 'Given and when using the same fixture should not evaluate it twice') |
| 50 | def test_given_and_when_using_the_same_fixture_should_not_evaluate_it_twice(): |
| 51 | """Given and when using the same fixture should not evaluate it twice.""" |
| 52 | |
| 53 | |
| 54 | @given('1 have a fixture (appends 1 to a list) in reuse syntax') |
| 55 | def _(): |
| 56 | """1 have a fixture (appends 1 to a list) in reuse syntax.""" |
| 57 | raise NotImplementedError |
| 58 | |
| 59 | |
| 60 | @given('I have an empty list') |
| 61 | def _(): |
| 62 | """I have an empty list.""" |
| 63 | raise NotImplementedError |
| 64 | |
| 65 | |
| 66 | @when('I use this fixture') |
| 67 | def _(): |
| 68 | """I use this fixture.""" |
| 69 | raise NotImplementedError |
nothing calls this directly
no test coverage detected
searching dependent graphs…