Re: doctests not running
Just to follow-up, the syntax itself does not appear to be a problem:
>>> import doctest
>>> import osl_flatpages
>>> doctest.testmod(osl_flatpages.models, verbose=1)
Trying:
home_fp = Flatpage.objects.get(page_name="Home")
Expecting nothing
ok
Trying:
home_fp.get_absolute_url()
Expecting:
'/'
ok
Trying:
about_fp = Flatpage.objects.get(page_name="About")
Expecting nothing
ok
Trying:
about_fp.get_absolute_url()
Expecting:
'/about/'
ok
6 items had no tests:
osl_flatpages.models
osl_flatpages.models.Flatpage
osl_flatpages.models.Flatpage.DoesNotExist
osl_flatpages.models.Flatpage.MultipleObjectsReturned
osl_flatpages.models.Flatpage.__unicode__
osl_flatpages.models.Flatpage.save
1 items passed all tests:
4 tests in osl_flatpages.models.Flatpage.get_absolute_url
4 tests in 7 items.
4 passed and 0 failed.
Test passed.
TestResults(failed=0, attempted=4)
So the problem appears to be with the Django test runner not adding
the doctests to the test suite it runs. I'm still not sure how to fix
this issue unfortunately.
On Jul 10, 9:50 pm, Jeff <jeffreychar...@gmail.com> wrote:
> Hi,
>
> I have a rather complicated get_absolute_url method in a models.py
> file that I wanted to use two doctests to check. Unfortunately the
> doctests do not appear to run when I run python manage.py test
> according to the verbose output.
>
> Here is the method:
>
> def get_absolute_url(self):
> """
> Use urlconf to determine url name from page name and then use
> url name
> to get absolute url.
>
> Returns none if there is no url name associated with the page
> name.
>
> Test that homepage works:
> >>> home_fp = Flatpage.objects.get(page_name="Home")
> >>> home_fp.get_absolute_url()
> '/'
>
> Test that about page works:
> >>> about_fp = Flatpage.objects.get(page_name="About")
> >>> about_fp.get_absolute_url()
> '/about/'
> """
> from django.core.urlresolvers import reverse
> from urls import urlpatterns
>
> for urlpattern in urlpatterns:
> if (hasattr(urlpattern, "default_args") and
> "page" in urlpattern.default_args and
> urlpattern.default_args["page"] == self.page_name and
> hasattr(urlpattern, "name")):
>
> return reverse(urlpattern.name)
>
> return None
>
> And here is the test output:
> Installed 6 object(s) from 1 fixture(s)
> test_correct_template_loaded
> (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> test_description (osl_flatpages.tests.views.OslFlatpageTestCase) ...
> ok
> test_existent (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> test_nonexistent (osl_flatpages.tests.views.OslFlatpageTestCase) ...
> ok
> test_nontemplate_content
> (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> test_template_content
> (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> test_title (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
>
> ----------------------------------------------------------------------
> Ran 7 tests in 0.415s
>
> As you can see, there is no mention of the two doctests being run.
>
> Any ideas as to why the two doctests are not running?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home