Skip to content

Support multiple apps in testing initializer #1895

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

primal100
Copy link

@primal100 primal100 commented Feb 25, 2025

Description

Allows the intializer to accept a mapping of app names to module list, allowing more flexibility when testing, and allowing tests to run on models across multiple apps. This would also allow models to work where they have a foreign key to a model in another app. The previous modules list and app label still works as normal so compatibility will not be affected. If a dict of app names to modules is provided, the app_label kw argument is not used.

Motivation and Context

Particularly useful when integrating models from a third party library into your own application.
Issue created a while back: #1521

How Has This Been Tested?

This is something that needs to be discussed as at the moment intializer and finalizer is run as an autouse session fixture, so difficult to override for a single test. Coverage is not an issue as there are no new lines.

Possibilities include:

  • Changing initialize_tests fixture to use the new apps/module dict format in which case the older single list format would not be tested.
  • Create a completely separate tests directory which ignores the main conftest.py. Probably the main conftest.py would have to be moved into the current tests directory. The new tests directory would have it's own conftest.py using the new style initializer argument format

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added the changelog accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@primal100 primal100 changed the title Support modules as a dict of app names and module lists in testing initializer Support multiple apps in testing initializer Feb 26, 2025
Copy link

codspeed-hq bot commented Feb 26, 2025

CodSpeed Performance Report

Merging #1895 will not alter performance

Comparing primal100:develop (9c83354) with develop (40b427d)

Summary

✅ 16 untouched benchmarks

@primal100
Copy link
Author

Some checks are failing due to

UP007 Use `X | Y` for type annotations

However, this newer way of writing Union types was introduced in Python 3.10 and tortoise-orm still allows support for 3.9, so that's why I still used typing.Union.

@waketzheng
Copy link
Contributor

Some checks are failing due to

UP007 Use `X | Y` for type annotations

However, this newer way of writing Union types was introduced in Python 3.10 and tortoise-orm still allows support for 3.9, so that's why I still used typing.Union.

With this line from __future__ import annotations at the beginning of the file, you are able to use X | Y for Python3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants