Skip to content

Commit be20caf

Browse files
authored
Update pytests (#96)
* Update pytests * Add .env3 to the gitignore * Add pre-commit configuration * Use `black` for linting * Remove unused test dependencies * Configure black * Apply `black` formatting tool to the codebase * Fix version discovery * Delete test module that never run a test
1 parent 37e46da commit be20caf

13 files changed

+55
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.rej
33
*.py[cod]
44
/.env
5+
/.env3
56
*.orig
67

78
# C extensions

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/psf/black
5+
rev: 20.8b1
6+
hooks:
7+
- id: black
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v3.2.0
10+
hooks:
11+
- id: trailing-whitespace
12+
- id: end-of-file-fixer
13+
- id: check-yaml
14+
- id: check-added-large-files

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.black]
2+
line-length = 120
3+
target-version = ['py27', 'py35', 'py36', 'py37', 'py38']

pytest_factoryboy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""pytest-factoryboy public API."""
22
from .fixture import register, LazyFixture
33

4-
__version__ = '2.0.3'
4+
__version__ = "2.0.3"
55

66

77
__all__ = [

pytest_factoryboy/fixture.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ def get_model_name(factory_class):
144144
"""Get model fixture name by factory."""
145145
return (
146146
inflection.underscore(factory_class._meta.model.__name__)
147-
if not isinstance(factory_class._meta.model, str) else factory_class._meta.model)
147+
if not isinstance(factory_class._meta.model, str)
148+
else factory_class._meta.model
149+
)
148150

149151

150152
def get_factory_name(factory_class):
@@ -164,17 +166,15 @@ def is_dep(value):
164166
if isinstance(value, factory.RelatedFactory):
165167
return False
166168
if isinstance(value, factory.SubFactory) and get_model_name(value.get_factory()) == parent_model_name:
167-
return False
169+
return False
168170
if isinstance(value, factory.declarations.PostGeneration):
169171
# Dependency on extracted value
170172
return True
171173

172174
return True
173175

174176
return [
175-
SEPARATOR.join((model_name, attr))
176-
for attr, value in factory_class._meta.declarations.items()
177-
if is_dep(value)
177+
SEPARATOR.join((model_name, attr)) for attr, value in factory_class._meta.declarations.items() if is_dep(value)
178178
]
179179

180180

@@ -199,7 +199,8 @@ class Factory(factory_class):
199199
pass
200200

201201
Factory._meta.base_declarations = dict(
202-
(k, v) for k, v in Factory._meta.base_declarations.items()
202+
(k, v)
203+
for k, v in Factory._meta.base_declarations.items()
203204
if not isinstance(v, factory.declarations.PostGenerationDeclaration)
204205
)
205206
Factory._meta.post_declarations = factory.builder.DeclarationSet()
@@ -233,7 +234,7 @@ class Factory(factory_class):
233234
argname = "".join((prefix, attr))
234235
extra = {}
235236
for k, v in factory_class._meta.post_declarations.contexts[attr].items():
236-
if k == '':
237+
if k == "":
237238
continue
238239
post_attr = SEPARATOR.join((argname, k))
239240

@@ -339,10 +340,7 @@ def __init__(self, fixture):
339340
self.fixture = fixture
340341
if callable(self.fixture):
341342
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-
]
343+
self.args = [param.name for param in params if param.kind == param.POSITIONAL_OR_KEYWORD]
346344
else:
347345
self.args = [self.fixture]
348346

pytest_factoryboy/plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def defer(self, functions):
2727
self.deferred.append(functions)
2828

2929
def get_deps(self, request, fixture, deps=None):
30-
request = request.getfixturevalue('request')
30+
request = request.getfixturevalue("request")
3131

3232
if deps is None:
3333
deps = set([fixture])
34-
if fixture == 'request':
34+
if fixture == "request":
3535
return deps
3636

3737
for fixturedef in request._fixturemanager.getfixturedefs(fixture, request._pyfuncitem.parent.nodeid) or []:
@@ -43,7 +43,7 @@ def get_deps(self, request, fixture, deps=None):
4343

4444
def get_current_deps(self, request):
4545
deps = set()
46-
while hasattr(request, '_parent_request'):
46+
while hasattr(request, "_parent_request"):
4747
if request.fixturename and request.fixturename not in getattr(request, "_fixturedefs", {}):
4848
deps.add(request.fixturename)
4949
request = request._parent_request
@@ -113,6 +113,7 @@ def pytest_runtest_call(item):
113113
def pytest_addhooks(pluginmanager):
114114
"""Register plugin hooks."""
115115
from pytest_factoryboy import hooks
116+
116117
pluginmanager.add_hookspecs(hooks)
117118

118119

requirements-testing.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
mock
2-
pytest-pep8
3-
pytest-cov
4-
pytest-cache

setup.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
dirname = os.path.dirname(__file__)
1010

1111
long_description = (
12-
codecs.open(os.path.join(dirname, "README.rst"), encoding="utf-8").read() + "\n" +
13-
codecs.open(os.path.join(dirname, "AUTHORS.rst"), encoding="utf-8").read() + "\n" +
14-
codecs.open(os.path.join(dirname, "CHANGES.rst"), encoding="utf-8").read()
12+
codecs.open(os.path.join(dirname, "README.rst"), encoding="utf-8").read()
13+
+ "\n"
14+
+ codecs.open(os.path.join(dirname, "AUTHORS.rst"), encoding="utf-8").read()
15+
+ "\n"
16+
+ codecs.open(os.path.join(dirname, "CHANGES.rst"), encoding="utf-8").read()
1517
)
1618

17-
with codecs.open(os.path.join(dirname, 'pytest_factoryboy', '__init__.py'), encoding='utf-8') as fd:
18-
VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(fd.read()).group(1)
19+
with codecs.open(os.path.join(dirname, "pytest_factoryboy", "__init__.py"), encoding="utf-8") as fd:
20+
VERSION = re.compile(r'.*__version__ = "(.*?)"', re.S).match(fd.read()).group(1)
1921

2022
setup(
2123
name="pytest-factoryboy",

tests/test_attributes_field.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

tests/test_circular.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ def __init__(self, name):
2828

2929

3030
class AuthorFactory(factory.Factory):
31-
3231
class Meta:
3332
model = Author
3433

3534
name = "Charles Dickens"
3635

37-
book = factory.RelatedFactory('tests.test_circular.BookFactory', 'author')
36+
book = factory.RelatedFactory("tests.test_circular.BookFactory", "author")
3837

3938

4039
class BookFactory(factory.Factory):
41-
4240
class Meta:
4341
model = Book
4442

0 commit comments

Comments
 (0)