#12682: testcase not loading fixtures, no error message shown
-------------------------------------+-------------------------------------
               Reporter:             |        Owner:  nobody
  forgacs.attila@…                   |    Milestone:
                 Status:  reopened   |      Version:  1.2
              Component:  Testing    |     Keywords:  fixture testcase not
  framework                          |  loading
             Resolution:             |    Has patch:  0
           Triage Stage:             |  Needs tests:  0
  Unreviewed                         |
    Needs documentation:  0          |
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------
Changes (by slinkp):

 * status:  closed => reopened
 * version:  1.1 => 1.2
 * resolution:  wontfix =>


Comment:

 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:

 {{{
 --- testcases.py~       2011-03-08 14:54:32.819851869 -0500
 +++ testcases.py        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 @@
              transaction.rollback_unless_managed(using=conn)

  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():

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12682#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to