Change name: instance_method_mock_fixture() -> late_instance_mock_fixture()
authorKarl O. Pinc <kop@karlpinc.com>
Sat, 16 Mar 2024 21:17:04 +0000 (16:17 -0500)
committerKarl O. Pinc <kop@karlpinc.com>
Sat, 16 Mar 2024 21:17:04 +0000 (16:17 -0500)
src/pgwui_develop/testing.py
tests/test_testing.py

index a704536bcab49d744e25bd8511605f219fed144c..8c81abeb74334612301719f9e1de8d671331c0f7 100644 (file)
@@ -1,4 +1,4 @@
-# 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.
@@ -57,9 +57,11 @@ def make_magicmock_fixture(module, method, autouse=False, autospec=False):
     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
index 8e3f7df029e5fc96b1542caf0c9b7e558d885cc5..a72458303ec8fc883428b22127ca4d669fe644de 100644 (file)
@@ -1,4 +1,4 @@
-# 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.
@@ -110,26 +110,30 @@ class TestClass():
 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