Skip to content

Commit

Permalink
Use inspect.signature() to avoid deprecation warning
Browse files Browse the repository at this point in the history
This avoids deprecation warning as inspect.getargspec()
is deprecated in Python 3.5+.
  • Loading branch information
Oliver Sauder authored and youtux committed Nov 13, 2018
1 parent 2f06b1b commit 53323a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pytest_factoryboy/fixture.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Factory boy fixture integration."""

import sys
import inspect

import factory
import factory.builder
Expand All @@ -10,6 +9,12 @@
import inflection
import pytest

from inspect import getmodule

if sys.version_info > (3, 0):
from inspect import signature
else:
from funcsigs import signature

SEPARATOR = "__"

Expand Down Expand Up @@ -316,7 +321,7 @@ def subfactory_fixture(request, factory_class):
def get_caller_module(depth=2):
"""Get the module of the caller."""
frame = sys._getframe(depth)
module = inspect.getmodule(frame)
module = getmodule(frame)
# Happens when there's no __init__.py in the folder
if module is None:
return get_caller_module(depth=depth) # pragma: no cover
Expand All @@ -333,7 +338,11 @@ def __init__(self, fixture):
"""
self.fixture = fixture
if callable(self.fixture):
self.args = list(inspect.getargspec(self.fixture).args)
params = signature(self.fixture).parameters.values()
self.args = [
param.name for param in params
if param.kind == param.POSITIONAL_OR_KEYWORD
]
else:
self.args = [self.fixture]

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"inflection",
"factory_boy>=2.10.0",
"pytest>=3.3.2",
'funcsigs;python_version<"3.0"',
],
# the following makes a plugin available to py.test
entry_points={
Expand Down

0 comments on commit 53323a4

Please sign in to comment.