Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def cleanup_patches(self):
# Unpatch before assertions, to make sure it is done if assertion fails.
testslide.mock_callable.unpatch_all_callable_mocks()
for assertion in self.assertions:
assertion()
def run(self):
try:
if self.example.skip:
raise Skip()
context_data = _ContextData(self.example, self.formatter)
if self.example.is_async:
self._async_run_all_hooks_and_example(context_data)
else:
self._sync_run_all_hooks_and_example(context_data)
finally:
sys.stdout.flush()
sys.stderr.flush()
testslide.mock_callable.unpatch_all_callable_mocks()
testslide.mock_constructor.unpatch_all_constructor_mocks()
testslide.patch_attribute.unpatch_all_mocked_attributes()
async def cleanup_patches(self):
# Unpatch before assertions, to make sure it is done if assertion fails.
testslide.mock_callable.unpatch_all_callable_mocks()
for assertion in self.assertions:
assertion()
def setUp(self):
testslide.mock_callable.register_assertion = lambda assertion: self.addCleanup(
assertion
)
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
self.addCleanup(testslide.mock_constructor.unpatch_all_constructor_mocks)
self.addCleanup(testslide.patch_attribute.unpatch_all_mocked_attributes)
super(TestCase, self).setUp()
import testslide.cli
alternative_target_module = testslide.cli.os.path
original_function = os.path.exists
# this is needed because `inspect.getframeinfo` calls `os.exist` under the hood
self.mock_callable(target, "exists").to_call_original()
self.mock_callable(target, "exists").for_call("found").to_return_value(True)
self.mock_callable(alternative_target, "exists").for_call(
"not_found"
).to_return_value(False)
self.assertTrue(target_module.exists("found"))
self.assertTrue(alternative_target_module.exists("found"))
self.assertFalse(target_module.exists("not_found"))
self.assertFalse(alternative_target_module.exists("not_found"))
testslide.mock_callable.unpatch_all_callable_mocks()
self.assertEqual(os.path.exists, original_function, "Unpatch did not work")