Skip to content

Commit 53323a4

Browse files
Oliver Sauderyoutux
Oliver Sauder
authored andcommitted
Use inspect.signature() to avoid deprecation warning
This avoids deprecation warning as inspect.getargspec() is deprecated in Python 3.5+.
1 parent 2f06b1b commit 53323a4

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pytest_factoryboy/fixture.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Factory boy fixture integration."""
22

33
import sys
4-
import inspect
54

65
import factory
76
import factory.builder
@@ -10,6 +9,12 @@
109
import inflection
1110
import pytest
1211

12+
from inspect import getmodule
13+
14+
if sys.version_info > (3, 0):
15+
from inspect import signature
16+
else:
17+
from funcsigs import signature
1318

1419
SEPARATOR = "__"
1520

@@ -316,7 +321,7 @@ def subfactory_fixture(request, factory_class):
316321
def get_caller_module(depth=2):
317322
"""Get the module of the caller."""
318323
frame = sys._getframe(depth)
319-
module = inspect.getmodule(frame)
324+
module = getmodule(frame)
320325
# Happens when there's no __init__.py in the folder
321326
if module is None:
322327
return get_caller_module(depth=depth) # pragma: no cover
@@ -333,7 +338,11 @@ def __init__(self, fixture):
333338
"""
334339
self.fixture = fixture
335340
if callable(self.fixture):
336-
self.args = list(inspect.getargspec(self.fixture).args)
341+
params = signature(self.fixture).parameters.values()
342+
self.args = [
343+
param.name for param in params
344+
if param.kind == param.POSITIONAL_OR_KEYWORD
345+
]
337346
else:
338347
self.args = [self.fixture]
339348

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"inflection",
4444
"factory_boy>=2.10.0",
4545
"pytest>=3.3.2",
46+
'funcsigs;python_version<"3.0"',
4647
],
4748
# the following makes a plugin available to py.test
4849
entry_points={

0 commit comments

Comments
 (0)