MCPcopy
hub / github.com/pytest-dev/pytest / test_inifilename

Method test_inifilename

testing/test_config.py:1421–1467  ·  testing/test_config.py::TestConfigFromdictargs.test_inifilename
(self, tmp_path: Path)

Source from the content-addressed store, hash-verified

1419 assert config.option.capture == class="st">"no"
1420
1421 def test_inifilename(self, tmp_path: Path) -> None:
1422 d1 = tmp_path.joinpath(class="st">"foo")
1423 d1.mkdir()
1424 p1 = d1.joinpath(class="st">"bar.ini")
1425 p1.touch()
1426 p1.write_text(
1427 textwrap.dedent(
1428 class="st">"""\
1429 [pytest]
1430 name = value
1431 class="st">"""
1432 ),
1433 encoding=class="st">"utf-8",
1434 )
1435
1436 inifilename = class="st">"../../foo/bar.ini"
1437 option_dict = {class="st">"inifilename": inifilename, class="st">"capture": class="st">"no"}
1438
1439 cwd = tmp_path.joinpath(class="st">"a/b")
1440 cwd.mkdir(parents=True)
1441 p2 = cwd.joinpath(class="st">"pytest.ini")
1442 p2.touch()
1443 p2.write_text(
1444 textwrap.dedent(
1445 class="st">"""\
1446 [pytest]
1447 name = wrong-value
1448 should_not_be_set = true
1449 class="st">"""
1450 ),
1451 encoding=class="st">"utf-8",
1452 )
1453 with MonkeyPatch.context() as mp:
1454 mp.chdir(cwd)
1455 config = Config.fromdictargs(option_dict, [])
1456 inipath = absolutepath(inifilename)
1457
1458 assert config.args == [str(cwd)]
1459 assert config.option.inifilename == inifilename
1460 assert config.option.capture == class="st">"no"
1461
1462 class="cm"># this indicates this is the file used for getting configuration values
1463 assert config.inipath == inipath
1464 assert config._inicfg.get(class="st">"name") == ConfigValue(
1465 class="st">"value", origin=class="st">"file", mode=class="st">"ini"
1466 )
1467 assert config._inicfg.get(class="st">"should_not_be_set") is None
1468
1469
1470def test_options_on_small_file_do_not_blow_up(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 8

absolutepathFunction · 0.90
ConfigValueClass · 0.90
write_textMethod · 0.80
contextMethod · 0.80
fromdictargsMethod · 0.80
mkdirMethod · 0.45
chdirMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected