我有几个用pytest编写的测试文件:
test_foo.py:
class TestFoo:
def test_foo_one(self, current_locale):
# some actions with locale
# assert
def test_foo_two(self, current_locale):
# some actions with locale
# assert
Run Code Online (Sandbox Code Playgroud)
test_bar.py:
class TestBar:
def test_bar_one(self, current_locale):
# some actions with locale
# assert
def test_bar_two(self, current_locale):
# some actions with locale
# assert
Run Code Online (Sandbox Code Playgroud)
和conftest.py:
locales = ["da-DK", "de-DE", "en-GB", "en-US", "es-AR", "es-CO", "es-ES", "es-MX", "fi-FI"]
def pytest_generate_tests(metafunc):
metafunc.parametrize('current_locale', locales, scope='session')
Run Code Online (Sandbox Code Playgroud)
它允许为每个区域设置运行测试.
现在,我想创建一个我不需要locales的测试,它必须只运行一次. test_without_locales.py:
class TestNoLocales:
def test_no_locales(self):
# some …Run Code Online (Sandbox Code Playgroud)