File tree Expand file tree Collapse file tree 7 files changed +20
-26
lines changed Expand file tree Collapse file tree 7 files changed +20
-26
lines changed Original file line number Diff line number Diff line change 4848 - flake8-comprehensions==3.10
4949 - flake8-pytest-style==1.6
5050 - flake8-spellcheck==0.28
51- - flake8-unused-arguments==0.0.11
51+ - flake8-unused-arguments==0.0.12
5252 - flake8-noqa==1.2.9
5353 - pep8-naming==0.13.2
Original file line number Diff line number Diff line change 11[build-system ]
22build-backend = " hatchling.build"
3- requires = [" hatchling>=1.11" , " hatch-vcs>=0.2" ]
3+ requires = [" hatchling>=1.11.1 " , " hatch-vcs>=0.2" ]
44
55[project ]
66name = " pytest-env"
@@ -13,7 +13,7 @@ urls.Source = "https://github.com/pytest-dev/pytest-env"
1313urls.Tracker = " https://github.com/pytest-dev/pytest-env/issues"
1414requires-python = " >=3.7"
1515dependencies = [" pytest>=7.1.3" ]
16- optional-dependencies.test = [" coverage>=6.5" , " pytest-mock>=3.10" , " covdefaults>=2.2 " ]
16+ optional-dependencies.test = [" coverage>=6.5" , " pytest-mock>=3.10" ]
1717keywords = [" pytest" , " env" ]
1818classifiers = [
1919 " Development Status :: 5 - Production/Stable" ,
@@ -39,11 +39,12 @@ version.source = "vcs"
3939line-length = 120
4040
4141[tool .coverage ]
42- source = [" ${_COVERAGE_SRC} " , " ${_COVERAGE_TEST} " ]
42+ run. source = [" pytest_env " , " tests " ]
4343run.dynamic_context = " test_function"
44- run.plugins = [ " covdefaults " ]
44+ run.branch = true
4545run.parallel = true
46- report.fail_under = 100
46+ report.fail_under = 92
47+ report.show_missing = true
4748html.show_contexts = true
4849html.skip_covered = false
4950paths.source = [
Original file line number Diff line number Diff line change @@ -18,23 +18,20 @@ def pytest_load_initial_conftests(
1818 args : list [str ], early_config : pytest .Config , parser : pytest .Parser # noqa: U100
1919) -> None :
2020 """Load environment variables from configuration files."""
21- for e in early_config .getini ("env" ):
22- part = e .partition ("=" )
21+ for line in early_config .getini ("env" ):
22+ part = line .partition ("=" )
2323 key = part [0 ].strip ()
2424 value = part [2 ].strip ()
2525
26- # Replace environment variables in value. for instance:
27- # TEST_DIR={USER}/repo_test_dir.
26+ # Replace environment variables in value. for instance TEST_DIR={USER}/repo_test_dir.
2827 value = value .format (** os .environ )
2928
30- # use D: as a way to designate a default value
31- # that will only override env variables if they
32- # do not exist already
33- dkey = key .split ("D:" )
29+ # use D: as a way to designate a default value that will only override env variables if they do not exist
30+ default_key = key .split ("D:" )
3431 default_val = False
3532
36- if len (dkey ) == 2 :
37- key = dkey [1 ]
33+ if len (default_key ) == 2 :
34+ key = default_key [1 ]
3835 default_val = True
3936
4037 if not default_val or key not in os .environ :
Original file line number Diff line number Diff line change 44
55
66def test_works () -> None :
7- assert "MAGIC" not in os .environ
7+ assert os . environ [ "MAGIC" ] == os .environ [ "_PATCH" ]
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33from pathlib import Path
4- from shutil import copy2
54
65import pytest
76
8- _EXAMPLE = Path (__file__ ).parent / "example.py"
9-
107
118@pytest .fixture ()
129def example (testdir : pytest .Testdir ) -> pytest .Testdir :
10+ src = Path (__file__ ).parent / "example.py"
1311 dest = Path (str (testdir .tmpdir / "test_example.py" ))
14- # dest.symlink_to(_EXAMPLE) # for local debugging use this
15- copy2 (str (_EXAMPLE ), str (dest ))
12+ dest .symlink_to (src )
1613 return testdir
1714
1815
1916def test_simple (example : pytest .Testdir ) -> None :
17+ (example .tmpdir / "pytest.ini" ).write_text ("[pytest]\n env = MAGIC=alpha" , encoding = "utf-8" )
18+ example .monkeypatch .setenv ("_PATCH" , "alpha" )
2019 result = example .runpytest ()
2120 result .assert_outcomes (passed = 1 )
Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ minversion = 3.21
1616description = run the tests with pytest
1717setenv =
1818 COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}{/}.coverage.{envname}}
19- _COVERAGE_SRC = {envsitepackagesdir}{/}pytest_env
20- _COVERAGE_TEST = {toxinidir}{/}tests
2119extras =
2220 test
2321commands =
Original file line number Diff line number Diff line change 11addini
22addoption
33conftests
4- copy2
5- dkey
64getini
75hookimpl
86repo
97runpytest
8+ setenv
109testdir
1110tmpdir
1211tryfirst
You can’t perform that action at this time.
0 commit comments