From 2c1e9a415656aeca815b828c54d43c19634b25ec Mon Sep 17 00:00:00 2001 From: Petros Kalos Date: Fri, 6 Dec 2024 12:41:02 +0200 Subject: [PATCH] make use of inspect.unwrap to get the resolver code --- tests/test_permissions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 5fc080e3c..9bf939a6c 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -1,5 +1,5 @@ -import inspect import logging +from inspect import unwrap, getabsfile, getsourcelines, signature from unittest.mock import MagicMock, patch, ANY import pytest @@ -92,7 +92,7 @@ def test_permissions( fid = request.node.callspec.id.split('-')[-1] perm, reason = EXPECTED_RESOLVERS[fid].get(perm_type) assert_that(field.resolver).is_not_none() - msg = f'{fid} -> {field.resolver.__code__.co_filename}:{field.resolver.__code__.co_firstlineno}' + msg = f'{fid} -> {getabsfile(unwrap(field.resolver))}:{getsourcelines(unwrap(field.resolver))[1]}' logging.info(msg) # Setup mock context username = 'ausername' @@ -103,7 +103,7 @@ def test_permissions( mock_read_perm_name.return_value = perm mock_tenant_perm_name.return_value = perm - iargs = {arg: MagicMock() for arg in inspect.signature(field.resolver).parameters.keys()} + iargs = {arg: MagicMock() for arg in signature(field.resolver).parameters.keys()} # run test specific setup if required globals().get(f'setup_{fid}', lambda *_a, **b: None)(**locals()) # nosemgrep