Test that steps definition containing a yield statement work the same way as pytest fixture do, that is the code after the yield is executed during teardown.
(pytester)
| 575 | |
| 576 | |
| 577 | def test_steps_with_yield(pytester): |
| 578 | """Test that steps definition containing a yield statement work the same way as |
| 579 | pytest fixture do, that is the code after the yield is executed during teardown.""" |
| 580 | |
| 581 | pytester.makefile( |
| 582 | ".feature", |
| 583 | a="""\ |
| 584 | Feature: A feature |
| 585 | |
| 586 | Scenario: A scenario |
| 587 | When I setup stuff |
| 588 | Then stuff should be 42 |
| 589 | """, |
| 590 | ) |
| 591 | pytester.makepyfile( |
| 592 | textwrap.dedent( |
| 593 | """\ |
| 594 | import pytest |
| 595 | from pytest_bdd import given, when, then, scenarios |
| 596 | |
| 597 | scenarios("a.feature") |
| 598 | |
| 599 | @when("I setup stuff", target_fixture="stuff") |
| 600 | def _(): |
| 601 | print("Setting up...") |
| 602 | yield 42 |
| 603 | print("Tearing down...") |
| 604 | |
| 605 | |
| 606 | @then("stuff should be 42") |
| 607 | def _(stuff): |
| 608 | assert stuff == 42 |
| 609 | print("Asserted stuff is 42") |
| 610 | |
| 611 | """ |
| 612 | ) |
| 613 | ) |
| 614 | result = pytester.runpytest("-s") |
| 615 | result.assert_outcomes(passed=1) |
| 616 | result.stdout.fnmatch_lines( |
| 617 | [ |
| 618 | "*Setting up...*", |
| 619 | "*Asserted stuff is 42*", |
| 620 | "*Tearing down...*", |
| 621 | ] |
| 622 | ) |
| 623 | |
| 624 | |
| 625 | def test_lower_case_and(pytester): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…