MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_multiple_packages

Method test_multiple_packages

testing/python/fixtures.py:4183–4251  ·  view source on GitHub ↗

Complex test involving multiple package fixtures. Make sure teardowns are executed in order. . └── root ├── __init__.py ├── sub1 │ ├── __init__.py │ ├── conftest.py │ └── test_1.py └── sub2

(self, pytester: Pytester)

Source from the content-addressed store, hash-verified

4181 assert request.fixturenames == "s1 p1 m1 m2 c1 f2 f1".split()
4182
4183 def test_multiple_packages(self, pytester: Pytester) -> None:
4184 """Complex test involving multiple package fixtures. Make sure teardowns
4185 are executed in order.
4186 .
4187 └── root
4188 ├── __init__.py
4189 ├── sub1
4190 │ ├── __init__.py
4191 │ ├── conftest.py
4192 │ └── test_1.py
4193 └── sub2
4194 ├── __init__.py
4195 ├── conftest.py
4196 └── test_2.py
4197 """
4198 root = pytester.mkdir("root")
4199 root.joinpath("__init__.py").write_text("values = []")
4200 sub1 = root.joinpath("sub1")
4201 sub1.mkdir()
4202 sub1.joinpath("__init__.py").touch()
4203 sub1.joinpath("conftest.py").write_text(
4204 textwrap.dedent(
4205 """\
4206 import pytest
4207 from .. import values
4208 @pytest.fixture(scope="package")
4209 def fix():
4210 values.append("pre-sub1")
4211 yield values
4212 assert values.pop() == "pre-sub1"
4213 """
4214 )
4215 )
4216 sub1.joinpath("test_1.py").write_text(
4217 textwrap.dedent(
4218 """\
4219 from .. import values
4220 def test_1(fix):
4221 assert values == ["pre-sub1"]
4222 """
4223 )
4224 )
4225 sub2 = root.joinpath("sub2")
4226 sub2.mkdir()
4227 sub2.joinpath("__init__.py").touch()
4228 sub2.joinpath("conftest.py").write_text(
4229 textwrap.dedent(
4230 """\
4231 import pytest
4232 from .. import values
4233 @pytest.fixture(scope="package")
4234 def fix():
4235 values.append("pre-sub2")
4236 yield values
4237 assert values.pop() == "pre-sub2"
4238 """
4239 )
4240 )

Callers

nothing calls this directly

Calls 3

assertoutcomeMethod · 0.80
mkdirMethod · 0.45
inline_runMethod · 0.45

Tested by

no test coverage detected