Opened 9 years ago

Closed 8 years ago

#12682 closed (wontfix)

testcase not loading fixtures, no error message shown

Reported by: forgacs.attila@… Owned by: nobody
Component: Testing framework Version: 1.2
Severity: Keywords: fixture testcase not loading
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


class SimpleTest(TestCase):

fixtures = ['testvectors.json', 'testusers']

  1. Verbosity is set to "2"
  2. fixtures reside in directory called "fixtures"
  3. loaddata works !
  4. using JSON fixtures.

Problem: When running test case fixtures are not loaded, no error message is shown.
In fact, the word testvectors are not even present in the log.
The only thing that the testcase wants to load is the initial_data
which is nonexistent.

Change History (5)

comment:1 Changed 9 years ago by forgacs.attila@…

Got it working, there is no output about loading of fixtures.
Suggestion: At least on VERBOSITY == 2, log the loading of fixtures
to stdout.

comment:2 Changed 9 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

Fixtures are loaded at the start of *every* test in a test case. Printing log messages at *any* verbosity would be exceedingly obnoxious.

comment:3 Changed 9 years ago by anonymous

Understood, valid points there.
What about a fixture validation just like model validation,
that is done once for a complete testcase ?
Just like runserver does ?

comment:4 Changed 8 years ago by Paul Winkler

Resolution: wontfix
Status: closedreopened
Version: 1.11.2

Straw man patch against django 1.2.3 to print fixture errors only once per test run, works for me but it's just a quick hack:

---	2011-03-08 14:54:32.819851869 -0500
+++	2011-03-08 17:06:15.242352630 -0500
@@ -33,6 +33,22 @@
         value = [value]
     return value
+class FilteringStderr(object):
+    """
+    Prints a given message to stderr only once.
+    """
+    def __init__(self):
+        self.lines_seen = set()
+    def write(self, data):
+        import sys
+        if data in self.lines_seen:
+            return
+        self.lines_seen.add(data)
+        sys.stderr.write(data)
+filtered_stderr = FilteringStderr()
 real_commit = transaction.commit
 real_rollback = transaction.rollback
 real_enter_transaction_management = transaction.enter_transaction_management
@@ -210,6 +226,7 @@
 class TransactionTestCase(unittest.TestCase):
     def _pre_setup(self):
         """Performs any pre-test setup. This includes:
@@ -235,9 +252,13 @@
             call_command('flush', verbosity=0, interactive=False, database=db)
             if hasattr(self, 'fixtures'):
-                # We have to use this slightly awkward syntax due to the fact
-                # that we're using *args and **kwargs together.
-                call_command('loaddata', *self.fixtures, **{'verbosity': 0, 'database': db})
+                self._loaddata(db)
+    def _loaddata(self, db, commit=True):
+        # We have to use this slightly awkward syntax due to the fact
+        # that we're using *args and **kwargs together.
+        call_command('loaddata', *self.fixtures, **{'verbosity': 0, 'database': db, 'stderr': filtered_stderr, 'commit': commit})
     def _urlconf_setup(self):
         if hasattr(self, 'urls'):
@@ -506,11 +527,7 @@
         for db in databases:
             if hasattr(self, 'fixtures'):
-                call_command('loaddata', *self.fixtures, **{
-                                                            'verbosity': 0,
-                                                            'commit': False,
-                                                            'database': db
-                                                            })
+                self._loaddata(db, commit=False)
     def _fixture_teardown(self):
         if not connections_support_transactions():

comment:5 Changed 8 years ago by Russell Keith-Magee

Resolution: wontfix
Status: reopenedclosed

Please don't reopen tickets that have been closed wontfix. If you want to discuss reopening a ticket, please start a thread on django-dev.

As for the proposed 'strawman' fix -- that patch requires that you store all output generated by the fixture loading process. This could get expensive, and fast.

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