File tree 7 files changed +20
-26
lines changed
7 files changed +20
-26
lines changed Original file line number Diff line number Diff line change 48
48
- flake8-comprehensions==3.10
49
49
- flake8-pytest-style==1.6
50
50
- flake8-spellcheck==0.28
51
- - flake8-unused-arguments==0.0.11
51
+ - flake8-unused-arguments==0.0.12
52
52
- flake8-noqa==1.2.9
53
53
- pep8-naming==0.13.2
Original file line number Diff line number Diff line change 1
1
[build-system ]
2
2
build-backend = " hatchling.build"
3
- requires = [" hatchling>=1.11" , " hatch-vcs>=0.2" ]
3
+ requires = [" hatchling>=1.11.1 " , " hatch-vcs>=0.2" ]
4
4
5
5
[project ]
6
6
name = " pytest-env"
@@ -13,7 +13,7 @@ urls.Source = "https://github.com/pytest-dev/pytest-env"
13
13
urls.Tracker = " https://github.com/pytest-dev/pytest-env/issues"
14
14
requires-python = " >=3.7"
15
15
dependencies = [" 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" ]
17
17
keywords = [" pytest" , " env" ]
18
18
classifiers = [
19
19
" Development Status :: 5 - Production/Stable" ,
@@ -39,11 +39,12 @@ version.source = "vcs"
39
39
line-length = 120
40
40
41
41
[tool .coverage ]
42
- source = [" ${_COVERAGE_SRC} " , " ${_COVERAGE_TEST} " ]
42
+ run. source = [" pytest_env " , " tests " ]
43
43
run.dynamic_context = " test_function"
44
- run.plugins = [ " covdefaults " ]
44
+ run.branch = true
45
45
run.parallel = true
46
- report.fail_under = 100
46
+ report.fail_under = 92
47
+ report.show_missing = true
47
48
html.show_contexts = true
48
49
html.skip_covered = false
49
50
paths.source = [
Original file line number Diff line number Diff line change @@ -18,23 +18,20 @@ def pytest_load_initial_conftests(
18
18
args : list [str ], early_config : pytest .Config , parser : pytest .Parser # noqa: U100
19
19
) -> None :
20
20
"""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 ("=" )
23
23
key = part [0 ].strip ()
24
24
value = part [2 ].strip ()
25
25
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.
28
27
value = value .format (** os .environ )
29
28
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:" )
34
31
default_val = False
35
32
36
- if len (dkey ) == 2 :
37
- key = dkey [1 ]
33
+ if len (default_key ) == 2 :
34
+ key = default_key [1 ]
38
35
default_val = True
39
36
40
37
if not default_val or key not in os .environ :
Original file line number Diff line number Diff line change 4
4
5
5
6
6
def 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 1
1
from __future__ import annotations
2
2
3
3
from pathlib import Path
4
- from shutil import copy2
5
4
6
5
import pytest
7
6
8
- _EXAMPLE = Path (__file__ ).parent / "example.py"
9
-
10
7
11
8
@pytest .fixture ()
12
9
def example (testdir : pytest .Testdir ) -> pytest .Testdir :
10
+ src = Path (__file__ ).parent / "example.py"
13
11
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 )
16
13
return testdir
17
14
18
15
19
16
def 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" )
20
19
result = example .runpytest ()
21
20
result .assert_outcomes (passed = 1 )
Original file line number Diff line number Diff line change @@ -16,8 +16,6 @@ minversion = 3.21
16
16
description = run the tests with pytest
17
17
setenv =
18
18
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}{/}.coverage.{envname}}
19
- _COVERAGE_SRC = {envsitepackagesdir}{/}pytest_env
20
- _COVERAGE_TEST = {toxinidir}{/}tests
21
19
extras =
22
20
test
23
21
commands =
Original file line number Diff line number Diff line change 1
1
addini
2
2
addoption
3
3
conftests
4
- copy2
5
- dkey
6
4
getini
7
5
hookimpl
8
6
repo
9
7
runpytest
8
+ setenv
10
9
testdir
11
10
tmpdir
12
11
tryfirst
You can’t perform that action at this time.
0 commit comments