Comments (8)
+1
from pytest-factoryboy.
2+ years later, no comments. Fantastic!
Open a PR or request a refund
from pytest-factoryboy.
2+ years later, no comments. Fantastic!
from pytest-factoryboy.
Confirmed, same error when using it in combination with SQLAlchemy.
from pytest-factoryboy.
Got this too
from pytest-factoryboy.
Anyone have any luck? I'm getting this with custom objects still on latest version
from pytest-factoryboy.
nowadays pytest-factoryboy gives this warning:
Using a <class 'list'> as model type for <ListFactory for <class 'list'>> is discouraged by pytest-factoryboy, as it assumes that the model name is 'list' when using it as SubFactory or RelatedFactory, which is too generic and probably not what you want.
You can giving an explicit name to the model by using:
model = named_model(list, "Foo")
factory_class = <class 'factory.base.ListFactory'>
model_cls = <class 'list'>
model_name = 'list'
Try that out, it should probably fix your issue.
from pytest-factoryboy.
anyway, this is the most correct way I can think of to fix the initial issue posted by @sanchez-escobar:
import factory
from pytest_factoryboy import register
class ClassA:
def __init__(self, val):
self.val = val
class ClassB:
def __init__(self, arr):
self.arr = arr
class ClassAFactory(factory.Factory):
"""TestClassA factory."""
class Meta:
model = ClassA
val = "test_value"
class ClassBFactory(factory.Factory):
"""TestClassB factory."""
class Meta:
model = ClassB
class Params:
arr_0 = factory.SubFactory(ClassAFactory)
arr = factory.LazyAttribute(lambda o: [o.arr_0])
register(ClassAFactory)
register(ClassBFactory)
def test_example_a(class_a):
"""
Assert that the nested list is properly tested
"""
assert class_a.val == "test_value"
def test_example_b(class_b):
"""
Assert that the nested list is properly tested
"""
assert len(class_b.arr) == 1
from pytest-factoryboy.
Related Issues (20)
- 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
- Broken support for Python 3.7 HOT 1
- 2.7.0: missing git version tag
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.