小编Ale*_*r T的帖子

从pytest_generate_tests中排除测试

我有几个用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)

python pytest

2
推荐指数
1
解决办法
297
查看次数

标签 统计

pytest ×1

python ×1