152 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			152 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			Python
		
	
	
	
| def test_show_only_active_fixtures(testdir):
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture
 | |
|         def _arg0():
 | |
|             """hidden arg0 fixture"""
 | |
|         @pytest.fixture
 | |
|         def arg1():
 | |
|             """arg1 docstring"""
 | |
|         def test_arg1(arg1):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         '*SETUP    F arg1*',
 | |
|         '*test_arg1 fixtures: arg1',
 | |
|         '*TEARDOWN F arg1*',
 | |
|     ])
 | |
|     assert "_arg0" not in result.stdout.str()
 | |
| 
 | |
| 
 | |
| def test_show_different_scopes(testdir):
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture
 | |
|         def arg_function():
 | |
|             """function scoped fixture"""
 | |
|         @pytest.fixture(scope='session')
 | |
|         def arg_session():
 | |
|             """session scoped fixture"""
 | |
|         def test_arg1(arg_session, arg_function):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         'SETUP    S arg_session*',
 | |
|         '*SETUP    F arg_function*',
 | |
|         '*test_arg1 fixtures: arg_function, arg_session',
 | |
|         '*TEARDOWN F arg_function*',
 | |
|         'TEARDOWN S arg_session*',
 | |
|     ])
 | |
| 
 | |
| 
 | |
| def test_show_nested_fixtures(testdir):
 | |
|     testdir.makeconftest('''
 | |
|         import pytest
 | |
|         @pytest.fixture(scope='session')
 | |
|         def arg_same():
 | |
|             """session scoped fixture"""
 | |
|         ''')
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture(scope='function')
 | |
|         def arg_same(arg_same):
 | |
|             """function scoped fixture"""
 | |
|         def test_arg1(arg_same):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         'SETUP    S arg_same*',
 | |
|         '*SETUP    F arg_same*',
 | |
|         '*test_arg1 fixtures: arg_same',
 | |
|         '*TEARDOWN F arg_same*',
 | |
|         'TEARDOWN S arg_same*',
 | |
|     ])
 | |
| 
 | |
| 
 | |
| def test_show_fixtures_with_autouse(testdir):
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture
 | |
|         def arg_function():
 | |
|             """function scoped fixture"""
 | |
|         @pytest.fixture(scope='session', autouse=True)
 | |
|         def arg_session():
 | |
|             """session scoped fixture"""
 | |
|         def test_arg1(arg_function):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         'SETUP    S arg_session*',
 | |
|         '*SETUP    F arg_function*',
 | |
|         '*test_arg1 fixtures: arg_function, arg_session',
 | |
|     ])
 | |
| 
 | |
| 
 | |
| def test_show_fixtures_with_parameters(testdir):
 | |
|     testdir.makeconftest('''
 | |
|         import pytest
 | |
|         @pytest.fixture(scope='session', params=['foo', 'bar'])
 | |
|         def arg_same():
 | |
|             """session scoped fixture"""
 | |
|         ''')
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture(scope='function')
 | |
|         def arg_other(arg_same):
 | |
|             """function scoped fixture"""
 | |
|         def test_arg1(arg_other):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         'SETUP    S arg_same?foo?',
 | |
|         'TEARDOWN S arg_same?foo?',
 | |
|         'SETUP    S arg_same?bar?',
 | |
|         'TEARDOWN S arg_same?bar?',
 | |
|     ])
 | |
| 
 | |
| 
 | |
| def test_show_fixtures_with_parameter_ids(testdir):
 | |
|     testdir.makeconftest('''
 | |
|         import pytest
 | |
|         @pytest.fixture(
 | |
|             scope='session', params=['foo', 'bar'], ids=['spam', 'ham'])
 | |
|         def arg_same():
 | |
|             """session scoped fixture"""
 | |
|         ''')
 | |
|     p = testdir.makepyfile('''
 | |
|         import pytest
 | |
|         @pytest.fixture(scope='function')
 | |
|         def arg_other(arg_same):
 | |
|             """function scoped fixture"""
 | |
|         def test_arg1(arg_other):
 | |
|             pass
 | |
|     ''')
 | |
| 
 | |
|     result = testdir.runpytest("--setup-only", p)
 | |
|     assert result.ret == 0
 | |
| 
 | |
|     result.stdout.fnmatch_lines([
 | |
|         'SETUP    S arg_same?spam?',
 | |
|         'SETUP    S arg_same?ham?',
 | |
|     ])
 |