Update for changes in fixture loading.

Review Request #14783 — Created Jan. 15, 2026 and submitted

Information

Djblets
release-5.x

Reviewers

Django 5.2 made an un-announced change that moved fixture loading to
happen at class init time rather than per-test-method. As part of this,
the _load_fixtures method has been made a @classmethod. This is a
fundamentally better approach, but causes numerous problems with our own
fixture code.

This change updates our FixturesCompilerMixin to operate at class-time
rather than at test function time. This requires changing the way we
hide the fixtures classvar from the parent class, since
__getattribute__ can't work.

The @add_fixtures decorator is now a performance hit rather than a
performance benefit. In addition, the replace argument is no longer
possible (but luckily, nothing actually used that). I've added a warning
about the performance implications, but for now it's hidden behind an
environment variable because we use this decorator a lot.

Ran unit tests and verified that fixtures worked appropriately.

Summary ID
Update for changes in fixture loading.
Django 5.2 made an un-announced change that moved fixture loading to happen at class init time rather than per-test-method. As part of this, the `_load_fixtures` method has been made a `@classmethod`. This is a fundamentally better approach, but causes numerous problems with our own fixture code. This change updates our `FixturesCompilerMixin` to operate at class-time rather than at test function time. This requires changing the way we hide the `fixtures` classvar from the parent class, since `__getattribute__` can't work. The `@add_fixtures` decorator is now a performance hit rather than a performance benefit. In addition, the `replace` argument is no longer possible (but luckily, nothing actually used that). I've added a warning about the performance implications, but for now it's hidden behind an environment variable because we use this decorator a lot. Testing Done: Ran unit tests and verified that fixtures worked appropriately.
vozroonuuumnwwkwllsykxxkovwrwzsr
Description From Last Updated

redefinition of unused 'Sequence' from line 18 Column: 5 Error code: F811

reviewbotreviewbot

Is this still true with Django 5.2, now that they've moved to class init time instead of per test?

maubinmaubin

These groups are in the wrong order.

chipx86chipx86

The docs are missing the Returns.

chipx86chipx86

Can you place the trailing ) on here and the next multi-line string on the following line, a la lists/dicts, …

chipx86chipx86

So, I'm not sure we do want to remove this.. I believe we have a lot of tests across our …

chipx86chipx86

This was previously missing a , optional.

chipx86chipx86

For multi-line strings, can we move the ) to the following line, isolating the contents like we do multi-line lists/dicts? …

chipx86chipx86
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
maubin
  1. 
      
  2. djblets/testing/testcases.py (Diff revision 2)
     
     
     
     
     
    Show all issues

    Is this still true with Django 5.2, now that they've moved to class init time instead of per test?

    1. Yeah. It's much better than when it was per method, but it still calls the loaddata command per fixture file per test case class.

  3. 
      
david
chipx86
  1. 
      
  2. djblets/testing/decorators.py (Diff revision 3)
     
     
     
     
     
    Show all issues

    These groups are in the wrong order.

  3. djblets/testing/decorators.py (Diff revision 3)
     
     
     
     
     
     
    Show all issues

    The docs are missing the Returns.

  4. djblets/testing/decorators.py (Diff revision 3)
     
     
     
     
     
     
    Show all issues

    Can you place the trailing ) on here and the next multi-line string on the following line, a la lists/dicts, so the string's self-contained?

  5. djblets/testing/decorators.py (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
    Show all issues

    So, I'm not sure we do want to remove this.. I believe we have a lot of tests across our codebases that really do depend on fixtures being applied to specific tests, and would fail if we move all addfixture-specified tests down into the class. I think it'll be pretty messy.

    I get there's a performance hit, but I think there's still value here.

  6. djblets/testing/testcases.py (Diff revision 3)
     
     
    Show all issues

    This was previously missing a , optional.

  7. djblets/testing/testcases.py (Diff revision 3)
     
     
     
     
    Show all issues

    For multi-line strings, can we move the ) to the following line, isolating the contents like we do multi-line lists/dicts?

    Same with the sys.stderr.write below.

  8. 
      
david
maubin
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.x (3027dd5)