@@ -2597,11 +2597,13 @@ def test_bar(arg1):
2597
2597
''' )
2598
2598
2599
2599
2600
+ @pytest .mark .parametrize ('flavor' , ['fixture' , 'yield_fixture' ])
2600
2601
class TestContextManagerFixtureFuncs :
2601
- def test_simple (self , testdir ):
2602
+
2603
+ def test_simple (self , testdir , flavor ):
2602
2604
testdir .makepyfile ("""
2603
2605
import pytest
2604
- @pytest.yield_fixture
2606
+ @pytest.{flavor}
2605
2607
def arg1():
2606
2608
print ("setup")
2607
2609
yield 1
@@ -2611,7 +2613,7 @@ def test_1(arg1):
2611
2613
def test_2(arg1):
2612
2614
print ("test2 %s" % arg1)
2613
2615
assert 0
2614
- """ )
2616
+ """ . format ( flavor = flavor ) )
2615
2617
result = testdir .runpytest ("-s" )
2616
2618
result .stdout .fnmatch_lines ("""
2617
2619
*setup*
@@ -2622,10 +2624,10 @@ def test_2(arg1):
2622
2624
*teardown*
2623
2625
""" )
2624
2626
2625
- def test_scoped (self , testdir ):
2627
+ def test_scoped (self , testdir , flavor ):
2626
2628
testdir .makepyfile ("""
2627
2629
import pytest
2628
- @pytest.yield_fixture (scope="module")
2630
+ @pytest.{flavor} (scope="module")
2629
2631
def arg1():
2630
2632
print ("setup")
2631
2633
yield 1
@@ -2634,7 +2636,7 @@ def test_1(arg1):
2634
2636
print ("test1 %s" % arg1)
2635
2637
def test_2(arg1):
2636
2638
print ("test2 %s" % arg1)
2637
- """ )
2639
+ """ . format ( flavor = flavor ) )
2638
2640
result = testdir .runpytest ("-s" )
2639
2641
result .stdout .fnmatch_lines ("""
2640
2642
*setup*
@@ -2643,94 +2645,63 @@ def test_2(arg1):
2643
2645
*teardown*
2644
2646
""" )
2645
2647
2646
- def test_setup_exception (self , testdir ):
2648
+ def test_setup_exception (self , testdir , flavor ):
2647
2649
testdir .makepyfile ("""
2648
2650
import pytest
2649
- @pytest.yield_fixture (scope="module")
2651
+ @pytest.{flavor} (scope="module")
2650
2652
def arg1():
2651
2653
pytest.fail("setup")
2652
2654
yield 1
2653
2655
def test_1(arg1):
2654
2656
pass
2655
- """ )
2657
+ """ . format ( flavor = flavor ) )
2656
2658
result = testdir .runpytest ("-s" )
2657
2659
result .stdout .fnmatch_lines ("""
2658
2660
*pytest.fail*setup*
2659
2661
*1 error*
2660
2662
""" )
2661
2663
2662
- def test_teardown_exception (self , testdir ):
2664
+ def test_teardown_exception (self , testdir , flavor ):
2663
2665
testdir .makepyfile ("""
2664
2666
import pytest
2665
- @pytest.yield_fixture (scope="module")
2667
+ @pytest.{flavor} (scope="module")
2666
2668
def arg1():
2667
2669
yield 1
2668
2670
pytest.fail("teardown")
2669
2671
def test_1(arg1):
2670
2672
pass
2671
- """ )
2673
+ """ . format ( flavor = flavor ) )
2672
2674
result = testdir .runpytest ("-s" )
2673
2675
result .stdout .fnmatch_lines ("""
2674
2676
*pytest.fail*teardown*
2675
2677
*1 passed*1 error*
2676
2678
""" )
2677
2679
2678
- def test_yields_more_than_one (self , testdir ):
2680
+ def test_yields_more_than_one (self , testdir , flavor ):
2679
2681
testdir .makepyfile ("""
2680
2682
import pytest
2681
- @pytest.yield_fixture (scope="module")
2683
+ @pytest.{flavor} (scope="module")
2682
2684
def arg1():
2683
2685
yield 1
2684
2686
yield 2
2685
2687
def test_1(arg1):
2686
2688
pass
2687
- """ )
2689
+ """ . format ( flavor = flavor ) )
2688
2690
result = testdir .runpytest ("-s" )
2689
2691
result .stdout .fnmatch_lines ("""
2690
2692
*fixture function*
2691
2693
*test_yields*:2*
2692
2694
""" )
2693
2695
2694
-
2695
- def test_no_yield (self , testdir ):
2696
- testdir .makepyfile ("""
2697
- import pytest
2698
- @pytest.yield_fixture(scope="module")
2699
- def arg1():
2700
- return 1
2701
- def test_1(arg1):
2702
- pass
2703
- """ )
2704
- result = testdir .runpytest ("-s" )
2705
- result .stdout .fnmatch_lines ("""
2706
- *yield_fixture*requires*yield*
2707
- *yield_fixture*
2708
- *def arg1*
2709
- """ )
2710
-
2711
- def test_yield_not_allowed_in_non_yield (self , testdir ):
2712
- testdir .makepyfile ("""
2713
- import pytest
2714
- @pytest.fixture(scope="module")
2715
- def arg1():
2716
- yield 1
2717
- def test_1(arg1):
2718
- pass
2719
- """ )
2720
- result = testdir .runpytest ("-s" )
2721
- result .stdout .fnmatch_lines ("""
2722
- *fixture*cannot use*yield*
2723
- *def arg1*
2724
- """ )
2725
-
2726
- def test_custom_name (self , testdir ):
2727
- testdir .makepyfile ("""
2728
- import pytest
2729
- @pytest.fixture(name='meow')
2730
- def arg1():
2731
- return 'mew'
2732
- def test_1(meow):
2733
- print(meow)
2734
- """ )
2735
- result = testdir .runpytest ("-s" )
2736
- result .stdout .fnmatch_lines ("*mew*" )
2696
+ # TODO: yield_fixture should work as well (this is bugged right now)
2697
+ def test_custom_name (testdir ):
2698
+ testdir .makepyfile ("""
2699
+ import pytest
2700
+ @pytest.fixture(name='meow')
2701
+ def arg1():
2702
+ return 'mew'
2703
+ def test_1(meow):
2704
+ print(meow)
2705
+ """ )
2706
+ result = testdir .runpytest ("-s" )
2707
+ result .stdout .fnmatch_lines ("*mew*" )
0 commit comments