Skip to content

Commit 59d909b

Browse files
authored
Fix test suite (#6)
1 parent 73196a1 commit 59d909b

File tree

7 files changed

+20
-26
lines changed

7 files changed

+20
-26
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ repos:
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

pyproject.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
build-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]
66
name = "pytest-env"
@@ -13,7 +13,7 @@ urls.Source = "https://github.com/pytest-dev/pytest-env"
1313
urls.Tracker = "https://github.com/pytest-dev/pytest-env/issues"
1414
requires-python = ">=3.7"
1515
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"]
1717
keywords = ["pytest", "env"]
1818
classifiers = [
1919
"Development Status :: 5 - Production/Stable",
@@ -39,11 +39,12 @@ version.source = "vcs"
3939
line-length = 120
4040

4141
[tool.coverage]
42-
source = ["${_COVERAGE_SRC}", "${_COVERAGE_TEST}"]
42+
run.source = ["pytest_env", "tests"]
4343
run.dynamic_context = "test_function"
44-
run.plugins = ["covdefaults"]
44+
run.branch = true
4545
run.parallel = true
46-
report.fail_under = 100
46+
report.fail_under = 92
47+
report.show_missing = true
4748
html.show_contexts = true
4849
html.skip_covered = false
4950
paths.source = [

src/pytest_env/plugin.py

+7-10
Original file line numberDiff line numberDiff 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:

tests/example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55

66
def test_works() -> None:
7-
assert "MAGIC" not in os.environ
7+
assert os.environ["MAGIC"] == os.environ["_PATCH"]

tests/test_env.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
from __future__ import annotations
22

33
from pathlib import Path
4-
from shutil import copy2
54

65
import pytest
76

8-
_EXAMPLE = Path(__file__).parent / "example.py"
9-
107

118
@pytest.fixture()
129
def 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

1916
def test_simple(example: pytest.Testdir) -> None:
17+
(example.tmpdir / "pytest.ini").write_text("[pytest]\nenv = MAGIC=alpha", encoding="utf-8")
18+
example.monkeypatch.setenv("_PATCH", "alpha")
2019
result = example.runpytest()
2120
result.assert_outcomes(passed=1)

tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ minversion = 3.21
1616
description = run the tests with pytest
1717
setenv =
1818
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}{/}.coverage.{envname}}
19-
_COVERAGE_SRC = {envsitepackagesdir}{/}pytest_env
20-
_COVERAGE_TEST = {toxinidir}{/}tests
2119
extras =
2220
test
2321
commands =

whitelist.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
addini
22
addoption
33
conftests
4-
copy2
5-
dkey
64
getini
75
hookimpl
86
repo
97
runpytest
8+
setenv
109
testdir
1110
tmpdir
1211
tryfirst

0 commit comments

Comments
 (0)