Skip to content

Commit 338961e

Browse files
committed
revert: remove missing stub warning; it's a little broken
This reverts commit 5fd4e6d.
1 parent b6b9df6 commit 338961e

File tree

7 files changed

+6
-149
lines changed

7 files changed

+6
-149
lines changed

decoy/__init__.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
"""Decoy test double stubbing and verification library."""
22
from os import linesep
33
from typing import cast, Any, Optional, Sequence, Type
4-
from warnings import warn
54

65
from .registry import Registry
76
from .spy import create_spy, SpyCall
87
from .stub import Stub
98
from .types import ClassT, FuncT, ReturnT
10-
from .warnings import MissingStubWarning
119

1210

1311
class Decoy:
1412
"""Decoy test double state container."""
1513

1614
_registry: Registry
17-
_warn_on_missing_stubs: bool
1815

19-
def __init__(
20-
self,
21-
warn_on_missing_stubs: bool = True,
22-
) -> None:
16+
def __init__(self) -> None:
2317
"""Initialize the state container for test doubles and stubs.
2418
2519
You should initialize a new Decoy instance for every test.
2620
27-
Arguments:
28-
warn_on_missing_stubs: Trigger a warning if a stub is called
29-
with arguments that do not match any of its rehearsals.
30-
3121
Example:
3222
```python
3323
import pytest
@@ -39,7 +29,6 @@ def decoy() -> Decoy:
3929
```
4030
"""
4131
self._registry = Registry()
42-
self._warn_on_missing_stubs = warn_on_missing_stubs
4332

4433
def create_decoy(self, spec: Type[ClassT], *, is_async: bool = False) -> ClassT:
4534
"""Create a class decoy for `spec`.
@@ -189,9 +178,6 @@ def _handle_spy_call(self, call: SpyCall) -> Any:
189178
if stub._rehearsal == call:
190179
return stub._act()
191180

192-
if self._warn_on_missing_stubs and len(stubs) > 0:
193-
warn(MissingStubWarning(call, stubs))
194-
195181
return None
196182

197183
def _build_verify_error(

decoy/registry.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_stubs_by_spy_id(self, spy_id: int) -> List[Stub[Any]]:
4040
"""Get a spy's stub list by identifier.
4141
4242
Arguments:
43-
spy_id: The unique identifier of the Spy to look up.
43+
spy_id: The unique identifer of the Spy to look up.
4444
4545
Returns:
4646
The list of stubs matching the given Spy.
@@ -51,7 +51,7 @@ def get_calls_by_spy_id(self, *spy_id: int) -> List[SpyCall]:
5151
"""Get a spy's call list by identifier.
5252
5353
Arguments:
54-
spy_id: The unique identifier of the Spy to look up.
54+
spy_id: The unique identifer of the Spy to look up.
5555
5656
Returns:
5757
The list of calls matching the given Spy.
@@ -83,7 +83,7 @@ def register_stub(self, spy_id: int, stub: Stub[Any]) -> None:
8383
"""Register a stub for tracking.
8484
8585
Arguments:
86-
spy_id: The unique identifier of the Spy to look up.
86+
spy_id: The unique identifer of the Spy to look up.
8787
stub: The stub to track.
8888
"""
8989
stub_list = self.get_stubs_by_spy_id(spy_id)

decoy/warnings.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/api.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@
55
::: decoy.stub.Stub
66

77
::: decoy.matchers
8-
9-
::: decoy.warnings

tests/conftest.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,5 @@
55

66
@pytest.fixture
77
def decoy() -> Decoy:
8-
"""Get a new instance of the Decoy state container.
9-
10-
Warnings are disabled for more quiet tests.
11-
"""
12-
return Decoy(warn_on_missing_stubs=False)
13-
14-
15-
@pytest.fixture
16-
def strict_decoy() -> Decoy:
17-
"""Get a new instance of the Decoy state container.
18-
19-
Warnings are left in the default enabled state. Use this fixture
20-
to test warning behavior.
21-
"""
8+
"""Get a new instance of the Decoy state container."""
229
return Decoy()

tests/test_warnings.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/test_when.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for the Decoy double creator."""
22
import pytest
33

4-
from decoy import Decoy, matchers, warnings
4+
from decoy import Decoy, matchers
55
from .common import some_func, SomeClass, SomeAsyncClass, SomeNestedClass
66

77

@@ -159,23 +159,3 @@ def _async_child(self) -> SomeAsyncClass:
159159
decoy.when(await stub._async_child.foo("hello")).then_return("world")
160160

161161
assert await stub._async_child.foo("hello") == "world"
162-
163-
164-
def test_no_stubbing_found_warning(strict_decoy: Decoy) -> None:
165-
"""It should raise a warning if a stub is configured and then called incorrectly."""
166-
stub = strict_decoy.create_decoy_func(spec=some_func)
167-
168-
strict_decoy.when(stub("hello")).then_return("world")
169-
170-
with pytest.warns(warnings.MissingStubWarning):
171-
stub("h3110")
172-
173-
174-
@pytest.mark.filterwarnings("error::UserWarning")
175-
def test_no_stubbing_found_warnings_disabled(decoy: Decoy) -> None:
176-
"""It should not raise a warning if warn_on_missing_stub is disabled."""
177-
stub = decoy.create_decoy_func(spec=some_func)
178-
179-
decoy.when(stub("hello")).then_return("world")
180-
181-
stub("h3110")

0 commit comments

Comments
 (0)