Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#14049 closed Cleanup/optimization (fixed)

Fixture loading should be skipped for TestCase decorated with @skip*

Reported by: zimnyx Owned by: PaulM
Component: Testing framework Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


TransactionTestCase overrides unittest.TestCase.__call__() and always runs _fixture_setup(), even for skipped tests (decorated with @skip* from unittest).
It makes no sense at all and it's really waste of time to wait for those fixtures to load.

class TransactionTestCase(unittest.TestCase):
    def _pre_setup(self):
        """Performs any pre-test setup. This includes:

            * Flushing the database.
            * If the Test Case class has a 'fixtures' member, installing the
              named fixtures.
            * If the Test Case class has a 'urls' member, replace the
              ROOT_URLCONF with it.
            * Clearing the mail test outbox.
        mail.outbox = []

    # ...

    def __call__(self, result=None):
        Wrapper around default __call__ method to perform common Django test
        set up. This means that user-defined Test Cases aren't required to
        include a call to super().setUp().
        self.client = Client()
            self._pre_setup()   # LOAD FOR EVERY TestCase
        except (KeyboardInterrupt, SystemExit):
        except Exception:
            import sys
            result.addError(self, sys.exc_info())
        super(TransactionTestCase, self).__call__(result)  # HERE @skip* decorators are honoured

Attachments (1)

14049.diff (2.0 KB) - added by ramiro 4 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 5 years ago by zimnyx

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

It's related to #12991

comment:2 Changed 5 years ago by PaulM

  • Owner changed from nobody to PaulM
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

I assume this applies when the patch from #12991 is applied and/or you're using Python 2.7 to test your app. I'm assigning this to myself, but I probably won't actually fix the problem until #12991 is resolved.

comment:3 Changed 5 years ago by PaulM

More broadly, the test running framework needs some cleanup in light of the changes to unittest, so this may get rolled into that.

comment:4 Changed 5 years ago by zimnyx

in fact I'm using unittest from 2.7 under Python 2.6 (I'm aware of existence unittest2, but unitest from 2.7 works just fine for me).

comment:5 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to Cleanup/optimization

Changed 4 years ago by ramiro

comment:6 Changed 4 years ago by ramiro

  • Easy pickings unset
  • Has patch set

comment:7 Changed 4 years ago by ramiro

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16369]:

Fixed #14049 -- Made our TestCase subclasses not load database fixtures (nor set up custom URLconfs) for test methods that are going to be skipped. Thanks zimnyx for the report.

comment:8 Changed 4 years ago by zimnyx

  • UI/UX unset

r16369 introduced new bug: #16372

comment:9 Changed 4 years ago by ramiro

In [16579]:

Fixed #16372 -- Changed strategy implemented in r16369 to fix #14049 to avoid affecting the statistics of test cases ran/skipped kept by unittest. Thanks zimnyx for the report.

Note: See TracTickets for help on using tickets.
Back to Top