Improve CHANGELOG and make test easier to understand for #570
This commit is contained in:
		
							parent
							
								
									487659d8b1
								
							
						
					
					
						commit
						35b3b1097f
					
				|  | @ -1 +1,2 @@ | ||||||
| Fix the scope behavior with indirect fixtures. | Fixed long standing issue where fixture scope was not respected when indirect fixtures were used during | ||||||
|  | parametrization. | ||||||
|  |  | ||||||
|  | @ -4012,43 +4012,53 @@ def test_fixture_named_request(testdir): | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_indirect_fixture(testdir): | def test_indirect_fixture_does_not_break_scope(testdir): | ||||||
|  |     """Ensure that fixture scope is respected when using indirect fixtures (#570)""" | ||||||
|     testdir.makepyfile( |     testdir.makepyfile( | ||||||
|         """ |         """ | ||||||
|         from collections import Counter |  | ||||||
| 
 |  | ||||||
|         import pytest |         import pytest | ||||||
| 
 | 
 | ||||||
|  |         instantiated  = [] | ||||||
| 
 | 
 | ||||||
|         @pytest.fixture(scope="session") |         @pytest.fixture(scope="session") | ||||||
|         def fixture_1(request, count=Counter()): |         def fixture_1(request): | ||||||
|             count[request.param] += 1 |             instantiated.append(("fixture_1", request.param)) | ||||||
|             yield count[request.param] |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         @pytest.fixture(scope="session") |         @pytest.fixture(scope="session") | ||||||
|         def fixture_2(request): |         def fixture_2(request): | ||||||
|             yield request.param |             instantiated.append(("fixture_2", request.param)) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         scenarios = [ |         scenarios = [ | ||||||
|             ("a", "a1"), |             ("A", "a1"), | ||||||
|             ("a", "a2"), |             ("A", "a2"), | ||||||
|             ("b", "b1"), |             ("B", "b1"), | ||||||
|             ("b", "b2"), |             ("B", "b2"), | ||||||
|             ("c", "c1"), |             ("C", "c1"), | ||||||
|             ("c", "c2"), |             ("C", "c2"), | ||||||
|         ] |         ] | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         @pytest.mark.parametrize( |         @pytest.mark.parametrize( | ||||||
|             "fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"] |             "fixture_1,fixture_2", scenarios, indirect=["fixture_1", "fixture_2"] | ||||||
|         ) |         ) | ||||||
|         def test_it(fixture_1, fixture_2): |         def test_create_fixtures(fixture_1, fixture_2): | ||||||
|             assert fixture_1 == 1 |             pass | ||||||
|             assert fixture_2[1] in ("1", "2") |  | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |         def test_check_fixture_instantiations(): | ||||||
|  |             assert instantiated == [ | ||||||
|  |                 ('fixture_1', 'A'), | ||||||
|  |                 ('fixture_2', 'a1'), | ||||||
|  |                 ('fixture_2', 'a2'), | ||||||
|  |                 ('fixture_1', 'B'), | ||||||
|  |                 ('fixture_2', 'b1'), | ||||||
|  |                 ('fixture_2', 'b2'), | ||||||
|  |                 ('fixture_1', 'C'), | ||||||
|  |                 ('fixture_2', 'c1'), | ||||||
|  |                 ('fixture_2', 'c2'), | ||||||
|  |             ] | ||||||
|     """ |     """ | ||||||
|     ) |     ) | ||||||
|     result = testdir.runpytest() |     result = testdir.runpytest() | ||||||
|     result.assert_outcomes(passed=6) |     result.assert_outcomes(passed=7) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue