-
Notifications
You must be signed in to change notification settings - Fork 55
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
Can't mock a @property without calling it? #339
Comments
For context - this was causing issues with a |
You'd be correct: this is how patching works. If the property is broken, then... things should break anyway :-/ There's no workaround: the property should be fixed.
This on the other hand... I'd expect to fail: a property is not... callable. It should have failed just as if one was trying to do import testslide
class SampleClass:
def __init__(self):
self.attr = "str"
class SampleTest(testslide.TestCase):
def test_prop_callable(self) -> None:
host = SampleClass()
self.mock_callable(host, "attr").to_return_value("patched")
self.assertEqual(host.attr, "patched") yields:
|
Property may call external service that is unavailable during tests and it will raise an error. This is what mocking should prevent. |
Hum... I see your point, that's fair. I think the way to address this is to add (yet) more complexity on top:
There are then 2 bugs to fix:
import testslide
class SampleClass:
@property
def prop(self) -> str:
raise RuntimeError("must not be called")
class SampleTest(testslide.TestCase):
def test_prop_attr(self) -> None:
host = SampleClass()
self.patch_attribute(host, "prop", "patched")
self.assertEqual(host.prop, "patched") |
@fornellas I can try working on this within the next 2 weeks. |
I'm using
TestSlide
version: 2.7.0Given:
When I run:
testslide patch_test.py
I expected this to happen:
prop()
is not calledBut, instead this happened:
prop()
is called, both when usingpatch_attribute
andmock_callable
.The text was updated successfully, but these errors were encountered: