MCPcopy Create free account
hub / github.com/pytest-dev/pytest-bdd / test_steps_with_yield

Function test_steps_with_yield

tests/feature/test_steps.py:577–622  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

575
576
577def 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="""\
584Feature: 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
625def test_lower_case_and(pytester):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…