-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix of issue 218 #219
base: master
Are you sure you want to change the base?
Fix of issue 218 #219
Conversation
Otherwise the metaclass will raise a TypeError because of an unkown attribute
for more information, see https://pre-commit.ci
It seems like the fix is not complete. Somewhere in the partial function model_fixture, the regular fixture name is called, and if the clashing factory does not have the same parameter, it will fail like this:
|
# Conflicts: # pytest_factoryboy/fixture.py
Hi @youtux , it's a-me again! I hope things are good. This has yet again become relevant for me. I know that the subfactory fixture name is generated using fixture = inflection.underscore(get_model_name(factory_class)) So the overriden fixture name is once again relevant. Consider the following model name: In [1]: import inflection
In [2]: inflection.underscore("B2BPartner")
Out[2]: 'b2_b_partner' This makes for a very weird fixture name, but looking at the code of the function, it makes sense. In my very specific case, with the code of my own PR, this ends up being: class B2BPartnerFactory(CustomFixtureDjangoModelFactory):
class Meta:
model = B2BPartner
fixture_name = "b2b_partner"
In [4]: inflection.underscore("b2b_partner")
Out[4]: 'b2b_partner' However, somewhere it's still looking for the regular fixture name, still investigating that.
What do you think about this? Thank you |
Hmm, I think I would prefer instead to change the Just thinking out loud, not sure if this would look good or if it would break something or if it's even feasible... |
I'm thinking of keeping a mapping between Factories and the factory fixture name using a WeakKeyDictionary "registry" constant in pytest-factoryboy (similar to what I did recently for pytest-bdd: pytest-dev/pytest-bdd#658) |
I think that could work. I am only wondering about the following thing: How would we define which is the "main" fixture? The one that right now would be created by calling register(YourFactory) with no name argument and is by default used for SubFactory. Would we define it with a boolean? Would we pass the name as a param to SubFactory? register(AuthorBookFactory) Results in an author_book fixture, which will also be used by the SubFactory. register(AuthorBookFactory, factory_fixture_name="authorbook") How do we make the SubFactory choose this one? Or maybe I am not seeing the whole picture you have in mind. If that all becomes clear to me, I wouldn't mind working on the code for it. Thanks for the very quick reply, Alessio! |
Good point, I didn't think about it! |
#218
This was the most backwards compatible way of implementing it that I could think of.
It works for my usecase scenario, but I am of course open to suggestions.
I would add testing but there are no tests involving Django models yet