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

Function test_package_with_modules

testing/python/collect.py:1416–1456  ·  view source on GitHub ↗

. └── root ├── __init__.py ├── sub1 │ ├── __init__.py │ └── sub1_1 │ ├── __init__.py │ └── test_in_sub1.py └── sub2 └── test └── test_in_sub2.py

(pytester: Pytester)

Source from the content-addressed store, hash-verified

1414
1415
1416def test_package_with_modules(pytester: Pytester) -> None:
1417 """
1418 .
1419 └── root
1420 ├── __init__.py
1421 ├── sub1
1422 │ ├── __init__.py
1423 │ └── sub1_1
1424 │ ├── __init__.py
1425 │ └── test_in_sub1.py
1426 └── sub2
1427 └── test
1428 └── test_in_sub2.py
1429
1430 """
1431 root = pytester.mkpydir("root")
1432 sub1 = root.joinpath("sub1")
1433 sub1_test = sub1.joinpath("sub1_1")
1434 sub1_test.mkdir(parents=True)
1435 for d in (sub1, sub1_test):
1436 d.joinpath("__init__.py").touch()
1437
1438 sub2 = root.joinpath("sub2")
1439 sub2_test = sub2.joinpath("test")
1440 sub2_test.mkdir(parents=True)
1441
1442 sub1_test.joinpath("test_in_sub1.py").write_text("def test_1(): pass")
1443 sub2_test.joinpath("test_in_sub2.py").write_text("def test_2(): pass")
1444
1445 # Execute from .
1446 result = pytester.runpytest("-v", "-s")
1447 result.assert_outcomes(passed=2)
1448
1449 # Execute from . with one argument "root"
1450 result = pytester.runpytest("-v", "-s", "root")
1451 result.assert_outcomes(passed=2)
1452
1453 # Chdir into package's root and execute with no args
1454 os.chdir(root)
1455 result = pytester.runpytest("-v", "-s")
1456 result.assert_outcomes(passed=2)
1457
1458
1459def test_package_ordering(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 5

assert_outcomesMethod · 0.80
mkpydirMethod · 0.45
mkdirMethod · 0.45
runpytestMethod · 0.45
chdirMethod · 0.45

Tested by

no test coverage detected