Skip to content

Commit 85c396c

Browse files
committed
updates tests
1 parent d9a7b6d commit 85c396c

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

src/pytest_echo/plugin.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_installed_distributions() -> list[tuple[str, str]]:
2727
"""Return a list of installed Distribution objects."""
2828
try:
2929
return [(d.name, d.version) for d in meta.distributions()]
30-
except (ImportError, AttributeError, TypeError):
30+
except (ImportError, AttributeError, TypeError): # pragma: no cover
3131
return []
3232

3333

@@ -142,10 +142,10 @@ def pytest_report_header(config: pytest.Config) -> str | None:
142142
data.extend(get_version(k))
143143
ret.append("\n".join([f" {k}: {v}" for k, v in sorted(data)]))
144144

145-
if config.option.echo_attribues:
145+
if config.option.echo_attributes:
146146
ret.extend([
147147
"Inspections:",
148-
"\n".join([f" {k}: {get_module_attribute(k)}" for k in config.option.echo_attribues]),
148+
"\n".join([f" {k}: {get_module_attribute(k)}" for k in config.option.echo_attributes]),
149149
])
150150
if not ret:
151151
ret = ["pytest-echo: nothing to echoing"]
@@ -192,7 +192,7 @@ def pytest_addoption(parser: pytest.Parser) -> None:
192192
group.addoption(
193193
"--echo-attr",
194194
action="append",
195-
dest="echo_attribues",
195+
dest="echo_attributes",
196196
default=[],
197197
help="attribute to print (full path)",
198198
)
@@ -208,18 +208,16 @@ def pytest_load_initial_conftests(
208208
for entry in _load_values(early_config):
209209
if entry.type in {"env", "envs", "echo_envs"}:
210210
early_config.option.echo_envs.append(entry.key)
211-
if entry.type in {"attr", "attribute", "echo_attribute"}:
211+
if entry.type in {"attr", "attribute", "echo_attributes"}:
212212
early_config.option.echo_attributes.append(entry.key)
213213
if entry.type in {"version", "echo_version"}:
214214
early_config.option.echo_versions.append(entry.key)
215215

216216

217217
def _load_values(early_config: pytest.Config) -> Iterator[Entry]:
218-
has_toml_conf = False
219-
if not has_toml_conf:
220-
for var in early_config.getini("echo_envs"):
221-
yield Entry(var, "env")
222-
for var in early_config.getini("echo_attributes"):
223-
yield Entry(var, "attr")
224-
for var in early_config.getini("echo_versions"):
225-
yield Entry(var, "version")
218+
for var in early_config.getini("echo_envs"):
219+
yield Entry(var, "env")
220+
for var in early_config.getini("echo_attributes"):
221+
yield Entry(var, "attr")
222+
for var in early_config.getini("echo_versions"):
223+
yield Entry(var, "version")

tests/test_config.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@ def test_ini_config(
3434

3535

3636
@pytest.mark.parametrize(
37-
("toml", "env"),
37+
("toml", "env", "expected"),
3838
[
3939
pytest.param(
4040
'[tool.pytest.ini_options]\necho_envs = ["ENV1", "ENV2", "ENV3"]',
4141
{"ENV1": "1", "ENV2": "2", "ENV3": "3"},
42+
" ENV2: 2",
43+
id="echo environment variables",
44+
),
45+
pytest.param(
46+
'[tool.pytest.ini_options]\necho_attributes = ["test_echo.ATTR_LIST"]',
47+
{},
48+
" test_echo.ATTR_LIST: [11, 12, 13, (21, 22)]",
49+
id="echo environment variables",
50+
),
51+
pytest.param(
52+
'[tool.pytest.ini_options]\necho_versions = ["pytest_echo"]',
53+
{},
54+
" pytest_echo: *",
4255
id="echo environment variables",
4356
),
4457
],
@@ -47,6 +60,7 @@ def test_toml_config(
4760
testdir: pytest.Testdir,
4861
toml: str,
4962
env: dict[str, str],
63+
expected: str,
5064
) -> None:
5165
new_env = {
5266
**env,
@@ -57,5 +71,5 @@ def test_toml_config(
5771
testdir.makepyfile("""def test_pass(request): pass""")
5872
testdir.makepyprojecttoml(toml)
5973
result = testdir.runpytest()
60-
result.stdout.fnmatch_lines([" ENV2: 2"])
74+
result.stdout.fnmatch_lines([expected])
6175
result.assert_outcomes(passed=1)

tests/test_echo.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
ATTR_DICT = {"key": "value"}
1212
ATTR_LIST = [11, 12, 13, (21, 22)]
1313
ATTR_COMPOSITE = {"key1": "value1", "key2": [11, 12, 13, 14], "key3": 99}
14-
14+
ATTR_SET = {11, 12, 13, (21, 22)}
1515

1616
class Dummy:
1717
attr = 1
@@ -91,15 +91,20 @@ def test_echo_attr_list(testdir: pytest.Testdir) -> None:
9191
result.stdout.fnmatch_lines([" test_echo.ATTR_LIST.2: 13"])
9292

9393

94+
def test_echo_attr_set(testdir: pytest.Testdir) -> None:
95+
result = testdir.runpytest("--echo-attr=test_echo.ATTR_SET.2")
96+
result.stdout.fnmatch_lines([" test_echo.ATTR_SET.2: (21, 22)"])
97+
98+
9499
def test_echo_attr_list_inner(testdir: pytest.Testdir) -> None:
95100
result = testdir.runpytest("--echo-attr=test_echo.ATTR_LIST.3.1")
96101
assert " test_echo.ATTR_LIST.3.1: 22" in result.stdout.lines
97102

98103

99104
def test_echo_attr_list_composite(testdir: pytest.Testdir) -> None:
100105
result = testdir.runpytest(
101-
"--echo-attr=test_echo.ATTR_COMPOSITE.key1",
102-
"--echo-attr=test_echo.ATTR_COMPOSITE.key2.3",
106+
"--echo-attr=test_echo.ATTR_COMPOSITE.key1",
107+
"--echo-attr=test_echo.ATTR_COMPOSITE.key2.3",
103108
)
104109
assert " test_echo.ATTR_COMPOSITE.key1: 'value1'" in result.stdout.lines
105110
assert " test_echo.ATTR_COMPOSITE.key2.3: 14" in result.stdout.lines

0 commit comments

Comments
 (0)