-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update test factories #6335
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
Update test factories #6335
Conversation
ckan/tests/controllers/test_admin.py
Outdated
@@ -233,10 +228,10 @@ def test_trash_view_sysadmin(self, app, sysadmin_env): | |||
# On the purge page | |||
assert "purge-all" in trash_response | |||
|
|||
def test_trash_no_datasets(self, app, sysadmin_env): | |||
def test_trash_no_datasets(self, app, sysadmin_env, package_factory): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call it dataset_factory
? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's possible.
I used "package" because I want to highlight that this dataset is not the only possible package type. In their own projects, people should create sub_factories for creating package factories with the non-dataset type.
And for dataset type, if the developer customizes it, then he can register a specific dataset_factory
fixture, with the package[type=dataset] that has set of fields sensible for this particular portal's dataset. While package_factory
is still available if he needs something more low-level
I know this is a matter of personal taste but I find more readable calling the factories explicitly to create instances that using the factory fixture, eg not sure than this: def test(user_factory):
user = user_factory(name="xxx") is more readable than this: def test():
user = factories.User(name="xxx") (I really don't like the I specially don't like it in cases where you need to pass a lot of fixtures to set up several factory instances, like here and I can imagine people being confused about whether to import the But perhaps I'm focusing too much on the syntax and missing the bigger picture here. How do these changes align with your wider work in tests? Do we need these changes to enable us something down the line? |
They are absolutely optional and I'm going to revert this particular piece (using fixtures instead of explicit factories). It's more an example of how people can(if they want) write tests. As for core tests - I prefer everyone to be comfortable with codebase much more than using fancy solutions :) I was thinking about different approaches and at the moment I can see a way of increasing speed without test factories. But I think, that:
Is it better? |
b7a72eb
to
0bb55c9
Compare
Hi, @amercader I've removed these mass changes from factories to fixtures. How does it feel now?
|
@smotornyuk Sorry it took a while to revisit this, it's looks good to me. |
Modernize test factories and add factoryboy fixtures.
New features:
faker
instead of number-sequences)Docs: factoryboy SQLAlchemy and pytest-factoryboy
Examples