Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt '[tool.pytest-enabler]' for configuration (PEP 518) #5

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v1.3.0
======

#4: pytest-enabler now uses ``[tool.pytest-enabler]`` for configuration
in accordance with :pep:`518#tool-table` (``[pytest.enabler]`` is deprecated).

v1.2.1
======

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

The 'enabler' plugin allows configuration of plugins if present, but omits the settings if the plugin is not present. For example, to configure black to be enabled if the plugin is present, but not when it is not, add the following to your pyproject.toml::

[pytest.enabler.black]
[tool.pytest-enabler.black]
addopts = "--black"

Known to work with the following plugins:
Expand Down
8 changes: 7 additions & 1 deletion pytest_enabler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import shlex
import sys
import warnings

import toml
from jaraco.context import suppress
Expand All @@ -24,7 +25,12 @@ def none_as_empty(ob):
def read_plugins(filename):
with open(filename) as strm:
defn = toml.load(strm)
return defn["pytest"]["enabler"]
if "pytest" in defn and "enabler" in defn["pytest"]:
msg = "pytest-enabler configuration should use the `[tool.pytest-enabler]` "
msg += "table in pyproject.toml (`[pytest.enabler]` is now deprecated)."
warnings.warn(msg, DeprecationWarning)
return defn["pytest"]["enabler"]
return defn["tool"]["pytest-enabler"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see this logic broken out as a compatibility shim that will be removed. I'll do that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 746a84d.



def pytest_load_initial_conftests(early_config, parser, args):
Expand Down
13 changes: 9 additions & 4 deletions tests/test_enabler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,24 @@ def tmpdir_cur(tmpdir):
yield tmpdir


def test_pytest_addoption(tmpdir_cur):
@pytest.mark.parametrize("config_table", ["tool.pytest-enabler", "pytest.enabler"])
def test_pytest_addoption(tmpdir_cur, config_table):
pathlib.Path('pyproject.toml').write_text(
textwrap.dedent(
"""
[pytest.enabler.black]
f"""
[{config_table}.black]
addopts = "--black"
"""
)
)
config = mock.MagicMock()
config.pluginmanager.has_plugin = lambda name: name == 'black'
args = []
enabler.pytest_load_initial_conftests(config, None, args)
if config_table.startswith("tool."):
enabler.pytest_load_initial_conftests(config, None, args)
else:
with pytest.warns(DeprecationWarning):
enabler.pytest_load_initial_conftests(config, None, args)
assert args == ['--black']

jaraco marked this conversation as resolved.
Show resolved Hide resolved

Expand Down