Ticket #5624: doctest-fixtures.diff

File doctest-fixtures.diff, 2.9 KB (added by jkocherhans, 8 years ago)

This time with tests.

  • django/test/testcases.py

     
    4747        # side effects on other tests.
    4848        transaction.rollback_unless_managed()
    4949
     50    def run(self, test, compileflags=None, out=None, clear_globs=True):
     51        call_command('flush', verbosity=0, interactive=False)
     52        if '__fixtures__' in test.globs:
     53            # We have to use this slightly awkward syntax due to the fact
     54            # that we're using *args and **kwargs together.
     55            call_command('loaddata', *test.globs['__fixtures__'], **{'verbosity': 0})
     56        return doctest.DocTestRunner.run(self, test, compileflags, out, clear_globs)
     57
    5058class TestCase(unittest.TestCase):
    5159    def _pre_setup(self):
    5260        """Performs any pre-test setup. This includes:
  • tests/regressiontests/doctest_fixtures/fixtures/doctest_fixture.xml

     
     1<?xml version="1.0" encoding="utf-8"?>
     2<django-objects version="1.0">
     3  <object pk="1" model="doctest_fixtures.band">
     4    <field type="CharField" name="name">The Doors</field>
     5  </object>
     6</django-objects>
  • tests/regressiontests/doctest_fixtures/models.py

     
     1"""
     2This object should have been loaded from the doctest_fixture.xml fixture.
     3
     4>>> Band.objects.get(pk=1)
     5<Band: The Doors>
     6"""
     7
     8from django.db import models
     9
     10class Band(models.Model):
     11    """
     12    This object should have been loaded from the doctest_fixture.xml fixture.
     13   
     14    >>> Band.objects.get(pk=1)
     15    <Band: The Doors>
     16    """
     17    name = models.CharField(max_length=100)
     18
     19    def __unicode__(self):
     20        """
     21        This object should have been loaded from the doctest_fixture.xml fixture.
     22       
     23        >>> Band.objects.get(pk=1)
     24        <Band: The Doors>
     25        """
     26        return self.name
     27
     28def test(self):
     29    """
     30    This object should have been loaded from the doctest_fixture.xml fixture.
     31   
     32    >>> Band.objects.get(pk=1)
     33    <Band: The Doors>
     34    """
     35    pass
     36
     37__fixtures__ = ['doctest_fixture.xml']
     38
     39__test__ = {'API_TESTS': """
     40This object should have been loaded from the doctest_fixture.xml fixture.
     41
     42>>> Band.objects.get(pk=1)
     43<Band: The Doors>
     44"""}
Back to Top