Skip to content

Commit

Permalink
make use of inspect.unwrap to get the resolver code
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkalos committed Dec 6, 2024
1 parent d72df13 commit 2c1e9a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import inspect
import logging
from inspect import unwrap, getabsfile, getsourcelines, signature
from unittest.mock import MagicMock, patch, ANY

import pytest
Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit 2c1e9a4

Please sign in to comment.