Skip to content

Commit

Permalink
fix: use logger instead of warning for TestPluginManager.discover (#283)
Browse files Browse the repository at this point in the history
* fix: use logger instead of warning for test plugin

* test: fix tests
  • Loading branch information
tlambert03 authored Apr 7, 2023
1 parent 27aa240 commit 54ed706
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/npe2/_pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import warnings
from typing import Optional, Union
from unittest.mock import patch
Expand All @@ -6,18 +7,17 @@

from npe2 import DynamicPlugin, PluginManager, PluginManifest

logger = logging.getLogger(__name__)


class TestPluginManager(PluginManager):
"""A PluginManager subclass suitable for use in testing."""

def discover(self, *_, **__) -> int:
"""Discovery is blocked in the TestPluginManager."""
import warnings

warnings.warn(
"TestPluginManager is unable to discover plugins. "
"Please use `tmp_plugin()` to add a plugin to this plugin manager.",
stacklevel=2,
logger.warning(
"NOTE: TestPluginManager refusing to discover plugins. "
"You may add plugins to this test plugin manager using `tmp_plugin()`."
)
return 0

Expand Down
8 changes: 5 additions & 3 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ def test_something_1(npe2pm):
CASE2 = """
import pytest
def test_something_2(npe2pm):
with pytest.warns(UserWarning, match='unable to discover plugins'):
npe2pm.discover()
def test_something_2(npe2pm, caplog):
npe2pm.discover()
assert "TestPluginManager refusing to discover plugins" in caplog.text
assert len(caplog.records) == 1
assert caplog.records[0].levelname == "WARNING"
"""

CASE3 = """
Expand Down

0 comments on commit 54ed706

Please sign in to comment.