Merge pull request #1782 from nicoddemus/invocation-fixtures-help
invocation-scoped fixtures show up once with --fixtures
This commit is contained in:
		
						commit
						226f2795ba
					
				|  | @ -1014,16 +1014,26 @@ def _showfixtures_main(config, session): | ||||||
|     fm = session._fixturemanager |     fm = session._fixturemanager | ||||||
| 
 | 
 | ||||||
|     available = [] |     available = [] | ||||||
|  |     seen = set() | ||||||
|  | 
 | ||||||
|     for argname, fixturedefs in fm._arg2fixturedefs.items(): |     for argname, fixturedefs in fm._arg2fixturedefs.items(): | ||||||
|         assert fixturedefs is not None |         assert fixturedefs is not None | ||||||
|         if not fixturedefs: |         if not fixturedefs: | ||||||
|             continue |             continue | ||||||
|         for fixturedef in fixturedefs: |         for fixturedef in fixturedefs: | ||||||
|             loc = getlocation(fixturedef.func, curdir) |             loc = getlocation(fixturedef.func, curdir) | ||||||
|  |             fixture_argname = fixturedef.argname | ||||||
|  |             # invocation-scoped fixtures have argname in the form | ||||||
|  |             # "<name>:<scope>" (for example: "monkeypatch:session"). | ||||||
|  |             if ':' in fixture_argname: | ||||||
|  |                 fixture_argname = fixture_argname.split(':')[0] | ||||||
|  |             if (fixture_argname, loc) in seen: | ||||||
|  |                 continue | ||||||
|  |             seen.add((fixture_argname, loc)) | ||||||
|             available.append((len(fixturedef.baseid), |             available.append((len(fixturedef.baseid), | ||||||
|                               fixturedef.func.__module__, |                               fixturedef.func.__module__, | ||||||
|                               curdir.bestrelpath(loc), |                               curdir.bestrelpath(loc), | ||||||
|                               fixturedef.argname, fixturedef)) |                               fixture_argname, fixturedef)) | ||||||
| 
 | 
 | ||||||
|     available.sort() |     available.sort() | ||||||
|     currentmodule = None |     currentmodule = None | ||||||
|  |  | ||||||
|  | @ -2725,6 +2725,13 @@ class TestShowFixtures: | ||||||
|                 Hi from test module |                 Hi from test module | ||||||
|         ''') |         ''') | ||||||
| 
 | 
 | ||||||
|  |     def test_show_invocation_fixtures(self, testdir): | ||||||
|  |         """py.test --fixtures should display invocation-scoped fixtures once. | ||||||
|  |         """ | ||||||
|  |         result = testdir.runpytest("--fixtures") | ||||||
|  |         result.stdout.fnmatch_lines('''monkeypatch''') | ||||||
|  |         assert 'monkeypatch:session' not in result.stdout.str() | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.mark.parametrize('flavor', ['fixture', 'yield_fixture']) | @pytest.mark.parametrize('flavor', ['fixture', 'yield_fixture']) | ||||||
| class TestContextManagerFixtureFuncs: | class TestContextManagerFixtureFuncs: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue