-# Copyright (C) 2015, 2018, 2020, 2021 The Meme Factory, Inc.
+# Copyright (C) 2015, 2018, 2020, 2021, 2024 The Meme Factory, Inc.
# http://www.karlpinc.com/
# This file is part of PGWUI_Develop.
return fix
-def instance_method_mock_fixture(method):
- '''Returns a pytest fixture that mocks an instance method of a class.
- "method" is a string.
+def late_instance_mock_fixture(method, ignore_deprecation=True):
+ '''Returns a pytest fixture that mocks a instance method.
+ "method" is the name of the instance or class method.
+ The function returned by the fixture takes the class instance to
+ be monkeypatched.
The fixture is called by the test function with the class instance
that's to be monkeypatched and the mock is returned for the
-# Copyright (C) 2018, 2019, 2020, 2021 The Meme Factory, Inc.
+# Copyright (C) 2018, 2019, 2020, 2021, 2024 The Meme Factory, Inc.
# http://www.karlpinc.com/
# This file is part of PGWUI_Develop.
mocked_method = testing.instance_method_mock_fixture('method_to_mock')
+#
+# late_instance_mock_fixture()
+#
+li_mocked_method = testing.late_instance_mock_fixture('method_to_mock')
+
+
@pytest.mark.unittest
@pytest.mark.integrationtest
-def test_instance_method_mock_fixture(mocked_method):
+def test_late_instance_mock_fixture(li_mocked_method):
# The mock of the instance method works
test_value = 'mocked value'
- cls = TestClass()
- mocked_method(cls).return_value = test_value
+ li_mocked_method(test_instance).return_value = test_value
- result = cls.method_to_mock()
+ result = test_instance.method_to_mock()
assert result == test_value
@pytest.mark.unittest
@pytest.mark.integrationtest
-def test_instance_method_mock_fixture_unmocked():
- # The test class works after the mocking
+def test_late_instance_mock_fixture_unmocked():
+ # The test function works after the mocking
- cls = TestClass()
- result = cls.method_to_mock()
+ result = test_instance.method_to_mock()
assert result == normal_return_value