Skip to content

Commit

Permalink
Merge pull request #153 from pytest-dev/prepare-release-2.2.1
Browse files Browse the repository at this point in the history
Prepare release 2.2.1
  • Loading branch information
youtux committed May 9, 2022
2 parents 4b1db99 + d79cf84 commit 19e2ff6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
25 changes: 25 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ Changelog
Unreleased
----------

2.2.1
----------
- ``@register()`` decorator now refuses kwargs after the initial specialization. This behaviour was mistakenly introduced in version 2.2.0, and it compicates the usage of the ``register`` function uncecessarily. For example, the following is not allowed anymore:

.. code-block:: python
# INVALID
register(
_name="second_author",
name="C.S. Lewis",
)(
AuthorFactory,
register_user="cs_lewis",
register_user__password="Aslan1",
)
# VALID
register(
AuthorFactory,
_name="second_author",
name="C.S. Lewis",
register_user="cs_lewis",
register_user__password="Aslan1",
)
2.2.0
----------
- Drop support for Python 3.6. We now support only python >= 3.7.
Expand Down
34 changes: 20 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,17 @@ by the name like "first", "second" or of another parent as "other":

.. code-block:: python
register(BookFactory) # book
register(BookFactory, "second_book") # second_book
register(AuthorFactory) # author
register(AuthorFactory, "second_author") # second_author
register(AuthorFactory) # author
register(AuthorFactory, "second_author") # second_author
# `register(...)` can be used as a decorator too
@register # book
@register(_name="second_book") # second_book
@register(_name="other_book") # other_book, book of another author
class BookFactory(factory.Factory):
class Meta:
model = Book
register(BookFactory, "other_book") # other_book, book of another author
@pytest.fixture
def other_book__author(second_author):
Expand Down Expand Up @@ -143,10 +147,10 @@ Integration

An example of factory_boy_ and pytest_ integration.

factories/__init__.py:

.. code-block:: python
# factories/__init__.py
import factory
from faker import Factory as FakerFactory
Expand All @@ -172,32 +176,37 @@ factories/__init__.py:
author = factory.SubFactory(AuthorFactory)
tests/conftest.py:
.. code-block:: python
# tests/conftest.py
from pytest_factoryboy import register
from factories import AuthorFactory, BookFactory
register(AuthorFactory)
register(BookFactory)
tests/test_models.py:
.. code-block:: python
# tests/test_models.py
from app.models import Book
from factories import BookFactory
def test_book_factory(book_factory):
"""Factories become fixtures automatically."""
assert book_factory is BookFactory
def test_book(book):
"""Instances become fixtures automatically."""
assert isinstance(book, Book)
@pytest.mark.parametrize("book__title", ["PyTest for Dummies"])
@pytest.mark.parametrize("author__name", ["Bill Gates"])
def test_parametrized(book):
Expand Down Expand Up @@ -342,10 +351,7 @@ pytest-factoryboy is trying to detect cycles and resolve post-generation depende
model = Bar
register(
BarFactory,
'bar',
)
register(BarFactory, "bar")
"""Forces 'set1' to be evaluated first."""
Expand Down
2 changes: 1 addition & 1 deletion pytest_factoryboy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""pytest-factoryboy public API."""
from .fixture import LazyFixture, register

__version__ = "2.2.0"
__version__ = "2.2.1"


__all__ = ("register", "LazyFixture")

0 comments on commit 19e2ff6

Please sign in to comment.