本文整理汇总了Python中pytest.lazy_fixture方法的典型用法代码示例。如果您正苦于以下问题:Python pytest.lazy_fixture方法的具体用法?Python pytest.lazy_fixture怎么用?Python pytest.lazy_fixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytest
的用法示例。
在下文中一共展示了pytest.lazy_fixture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fixture_in_parametrize_with_params
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_fixture_in_parametrize_with_params(testdir):
items = testdir.getitems("""
import pytest
@pytest.fixture(params=[1,2])
def one(request):
return request.param
@pytest.mark.parametrize('arg1,arg2', [
('val1', pytest.lazy_fixture('one')),
('val1', 'val2')
])
def test_func(arg1, arg2):
pass
""")
assert len(items) == 3
assert items[0].callspec.params['one'] == 1
assert items[1].callspec.params['one'] == 2
示例2: test_fixtures_in_parametrize_with_indirect
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_fixtures_in_parametrize_with_indirect(testdir):
items = testdir.getitems("""
import pytest
@pytest.fixture
def one():
pass
@pytest.fixture
def two():
pass
@pytest.mark.parametrize('arg1,one', [
('val1', pytest.lazy_fixture('two')),
], indirect=['one'])
def test_func(arg1, one):
pass
""")
assert len(items) == 1
assert items[0].callspec.params['one'].name == 'two'
示例3: test_fixtures_with_params_in_parametrize_with_indirect
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_fixtures_with_params_in_parametrize_with_indirect(testdir):
items = testdir.getitems("""
import pytest
@pytest.fixture
def one():
pass
@pytest.fixture(params=[1,2])
def two(request):
return request.param
@pytest.mark.parametrize('arg1,one', [
('val1', pytest.lazy_fixture('two')),
], indirect=['one'])
def test_func(arg1, one):
pass
""")
assert len(items) == 2
assert items[0].callspec.params['two'] == 1
assert items[1].callspec.params['two'] == 2
示例4: test_lazy_fixture_is_value_in_parametrize
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_is_value_in_parametrize(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture
def one():
return 1
@pytest.fixture
def two():
return 2
@pytest.mark.parametrize('arg1,arg2', [
pytest.lazy_fixture(('one', 'two'))
])
def test_func(arg1, arg2):
assert arg1 == 1
assert arg2 == 2
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=1)
示例5: test_lazy_fixture_is_value_in_parametrize_with_indirect
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_is_value_in_parametrize_with_indirect(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture
def one(request):
return request.param
@pytest.fixture
def two():
return 2
@pytest.mark.parametrize('one', [
pytest.lazy_fixture('two')
], indirect=True)
def test_func(one):
assert one == 2
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
示例6: test_lazy_fixture_as_param_of_fixture
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_as_param_of_fixture(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[
pytest.lazy_fixture('one'),
pytest.lazy_fixture('two')
])
def some(request):
return request.param
@pytest.fixture
def one():
return 1
@pytest.fixture
def two():
return 2
def test_func(some):
assert some in [1, 2]
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=2)
示例7: test_lazy_fixture_in_params_which_has_params
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_in_params_which_has_params(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2, 3])
def one(request):
return str(request.param)
@pytest.fixture
def two():
return 4
@pytest.fixture(params=[
pytest.lazy_fixture('one'),
pytest.lazy_fixture('two')
])
def some(request):
return request.param
def test_func(some):
assert some in {'1', '2', '3', 4}
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=4)
示例8: test_lazy_fixture_three_times_nested
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_three_times_nested(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[
1, 2, pytest.lazy_fixture('three')])
def one(request):
return str(request.param)
@pytest.fixture
def two():
return 4
@pytest.fixture
def three():
return 3
@pytest.fixture(params=[
pytest.lazy_fixture('one'),
pytest.lazy_fixture('two')
])
def some(request):
return request.param
def test_func(some):
assert some in {'1', '2', '3', 4}
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=4)
示例9: test_lazy_fixture_three_times_nested_with_one_failed
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_three_times_nested_with_one_failed(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[
1, 2, pytest.lazy_fixture('three')
])
def one(request):
return str(request.param)
@pytest.fixture
def two():
return 4
@pytest.fixture
def three():
return 5
@pytest.fixture(params=[
pytest.lazy_fixture('one'),
pytest.lazy_fixture('two')
])
def some(request):
return request.param
def test_func(some):
assert some in {'1', '2', '3', 4}
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=3, failed=1)
示例10: test_lazy_fixture_common_dependency_with_getfixturevalue
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_lazy_fixture_common_dependency_with_getfixturevalue(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2, 3])
def one(request):
return request.param
@pytest.fixture(params=[pytest.lazy_fixture('one')])
def as_str(request):
return str(request.getfixturevalue('one'))
@pytest.fixture(params=[pytest.lazy_fixture('one')])
def as_hex(request):
return hex(request.getfixturevalue('one'))
def test_as_str(as_str):
assert as_str in {'1', '2', '3'}
def test_as_hex(as_hex):
assert as_hex in {'0x1', '0x2', '0x3'}
def test_as_hex_vs_as_str(as_str, as_hex):
assert int(as_hex, 16) == int(as_str)
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=9)
示例11: test_issues2
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_issues2(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2, 3])
def one(request):
return request.param
@pytest.fixture(params=[pytest.lazy_fixture('one')])
def as_str(request):
return str(request.getfixturevalue('one'))
@pytest.mark.parametrize('val', ('a', 'b', 'c'))
def test_as_str(val, as_str):
combined = ''.join((val, as_str))
assert combined in {'a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3'}
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=9)
示例12: test_issues2_2
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_issues2_2(testdir):
testdir.makepyfile("""
import pytest
@pytest.fixture(params=[1, 2, 3])
def one(request):
return request.param
@pytest.fixture(params=[pytest.lazy_fixture('one')])
def as_str(request):
return str(request.getfixturevalue('one'))
@pytest.mark.parametrize('val, one', (
('a', '1'), ('b', '2'), ('c', '3')
), indirect=['one'])
def test_as_str(val, one, as_str):
combined = ''.join((val, as_str))
assert combined in {'a1', 'b2', 'c3'}
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=3)
示例13: test_issues3_autouse_fixtures_should_run_first
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_issues3_autouse_fixtures_should_run_first(testdir):
testdir.makepyfile("""
import pytest
gl = False
@pytest.fixture(autouse=True)
def auto_one():
global gl
gl = True
@pytest.fixture
def one():
return 1 if gl is True else -1
@pytest.mark.parametrize('arg1', [
pytest.lazy_fixture('one')
])
def test_some(arg1):
assert arg1 == 1
""")
reprec = testdir.inline_run('-s')
reprec.assertoutcome(passed=1)
示例14: test_issues10_xfail
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_issues10_xfail(testdir):
testdir.makepyfile("""
import pytest
def division(a, b):
return a / b
@pytest.fixture(params=[0])
def zero(request):
return request.param
@pytest.mark.parametrize(('a', 'b'), [
pytest.param(1, pytest.lazy_fixture('zero'), marks=pytest.mark.xfail(reason=ZeroDivisionError))
])
def test_division(a, b):
division(a, b)
""")
reprec = testdir.inline_run('-s', '-v')
reprec.assertoutcome(skipped=1)
示例15: test_issues12_lf_as_method_of_test_class
# 需要导入模块: import pytest [as 别名]
# 或者: from pytest import lazy_fixture [as 别名]
def test_issues12_lf_as_method_of_test_class(testdir):
testdir.makepyfile("""
import pytest
class TestModels:
@pytest.fixture
def one(self):
return 1
@pytest.mark.parametrize('a', [
pytest.lazy_fixture('one')
])
def test_lf(self, a):
assert a == 1
""")
reprec = testdir.inline_run('-s', '-v')
reprec.assertoutcome(passed=1)