예제 #1
0
파일: test_decoy.py 프로젝트: mcous/decoy
def test_reset(decoy: Decoy) -> None:
    """It should be able to reset its state."""
    subject = decoy.mock(cls=SomeClass)

    subject.foo("hello")
    decoy.reset()

    with pytest.raises(AssertionError):
        decoy.verify(subject.foo("hello"))
예제 #2
0
def decoy() -> Iterable[Decoy]:
    """Get a [decoy.Decoy][] container and [reset it][decoy.Decoy.reset] after the test.

    This function is function-scoped [pytest fixture][] that will be
    automatically inserted by the plugin.

    [pytest fixture]: https://docs.pytest.org/en/latest/how-to/fixtures.html

    Example:
        ```python
        def test_my_thing(decoy: Decoy) -> None:
            my_fake_func = decoy.mock()
            # ...
        ```
    """
    decoy = Decoy()
    yield decoy
    decoy.reset()
예제 #3
0
class DecoyTestCase(unittest.TestCase):
    """Decoy test case using unittest."""
    def setUp(self) -> None:
        """Set up before each test."""
        self.decoy = Decoy()

    def tearDown(self) -> None:
        """Clean up after each test."""
        self.decoy.reset()

    def test_when(self) -> None:
        """Test that self.decoy.when works."""
        mock = self.decoy.mock(cls=SomeClass)
        self.decoy.when(mock.foo("hello")).then_return("world")
        assert mock.foo("hello") == "world"

    def test_verify(self) -> None:
        """Test that self.decoy.verify works."""
        mock = self.decoy.mock(cls=SomeClass)
        mock.foo("hello")
        self.decoy.verify(mock.foo("hello"))