Comments (5)
Confirming that this has something to do with 2.9.0 (master) changes alone. I switched to FactoryBoy 2.8.1 and was able to avoid this issue for now.
from pytest-factoryboy.
I decided to ditch pytest-factoryboy and simply write a function that injects the factories as fixtures as-is, per the example in pytest-dev/pytest#2424
So, if your current conftest.py looks like this:
import factory
from pytest_factoryboy import register
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = User
username = factory.Sequence(lambda n: "TestUser%d" % n)
register(UserFactory)
try the following instead:
import factory
import pytest
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = User
username = factory.Sequence(lambda n: "TestUser%d" % n)
def register(factory_cls):
def generate_fixture(cls):
@pytest.fixture(scope="module")
def created_fixture():
return cls
return created_fixture
def to_snakecase(text):
"""
Converts text from CamelCase to snake_case
Source: https://stackoverflow.com/a/1176023/8981236
"""
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
# Inject the fixture with snakecase name
name = to_snakecase(factory_cls.__name__)
globals()[name] = generate_fixture(factory_cls)
register(UserFactory)
My current test suite works with it without modifications, and I no longer need pytest-factoryboy as the dependency. Your mileage may vary, so this may not be enough for your needs.
from pytest-factoryboy.
I also do report the same problems with 2.9.2
from pytest-factoryboy.
I would be happy to help with this but would prefer some feedback from the maintainers regarding their preferred way.
My preference would be to go along with factory_boy
changes / deprecations (that is, change postgen_declarations
to post_declarations .as_dict()
, more or less, which I did locally - it works and is easy) but that would require pytest-factoryboy
to specify the minimal factory_boy
version, possibly with a new major release and a note in the README about it.
Let me know what you guys think.
from pytest-factoryboy.
Please try 2.0.1
from pytest-factoryboy.
Related Issues (20)
- fixture not found using SubFactory HOT 1
- @register decorator should accept parameters HOT 2
- Allow to register factories in the class namespace.
- pytest-factoryboy seems to break factory.django.mute_signals HOT 4
- Fix tests/test_postgen_dependencies::test_postgen_related
- AttributeError using `LazyFixture` in `register()` HOT 5
- Parent factory model name disregards `_name` override. HOT 1
- Ship tests with source distribution HOT 1
- function uses no argument HOT 1
- UserWarning: UserWarning: Using a <class 'list'> as model type for <ListFactory for <class 'list'>> is discouraged HOT 5
- Error `fixture not found` if define `register(_name=)` for connected SubFactory which is connected with another SubFactory HOT 1
- DeprecationWarning with pytest 7.2.0 HOT 4
- PytestAssertRewriteWarning
- Feature request: override name of factory fixture? HOT 3
- Alternative for `register`
- register with type hints HOT 3
- Improve handling of `factory.Maybe`
- Request other fixtures in fixtures generated by register HOT 3
- How can I pass function-scope fixtures (e.g. db sessions) to each Factory in combination with pytest-asyncio?
- Question regarding of usage of LazyFixture in @pytest.mark.parametrize on alias instead of chained fixture. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-factoryboy.