I have the below Python==3.8
code, where I:
- Use
unittest.mock.patch
as a decorator - Preform a
patch(..., new=...)
:
from unittest.mock import patch
class Foo:
pass
class Bar:
pass
@patch(__name__ + f".Foo", new=Bar)
def test_foo(patched_Bar) -> None:
_ = 0 # Do stuff
Currently, this doesn't run, as the patched_Bar
argument is not supplied. How can I get the patched_Bar
arg to be passed in?
I know the below workaround exists, using with
, but I prefer not to do this, as it's less clean in my opinion.
def test_foo2() -> None:
with patch(__name__ + f".Foo", new=Bar) as patched_Bar:
_ = 0 # Do stuff