Opened 9 years ago

Closed 7 years ago

#6364 closed (fixed)

Allow test runner to execute individual doctests

Reported by: David Larlet Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords: testing
Cc: Russell Keith-Magee, Dan Fairs, Robin, David Larlet Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description (last modified by Russell Keith-Magee)

For the moment, you can specify a test case or even a single test method in this test case but you can't use more than one doctest file easily and run tests file by file for instance.

The attached patch allow you to run doctests from your tests/ directory one by one:

python test app.doctest_filename_without_extension

Or all at once:

python test app

You just need doctests files with ".txt" extension. Comments are welcome.

Update: doctests can already be split across files using __tests__. However, the ability to execute tests on a fine grained level would be useful.

Attachments (1)

patch_django_6364.diff (3.2 KB) - added by David Larlet 9 years ago.

Download all attachments as: .zip

Change History (14)

Changed 9 years ago by David Larlet

Attachment: patch_django_6364.diff added

comment:1 Changed 9 years ago by David Larlet

Needs documentation: unset
Needs tests: unset
Owner: changed from nobody to David Larlet
Patch needs improvement: unset

comment:2 Changed 9 years ago by Simon Greenhill <dev@…>

Has patch: set
Needs documentation: set
Triage Stage: UnreviewedReady for checkin

Sounds like a rather good idea. I'll move to RFC and see what core says

comment:3 Changed 9 years ago by David Larlet

Thanks Simon, I know there are a lot of improvements to do (better error handling, documentation, etc) but I'd like to know if core is interested in this approach before spending too much time on this.

comment:4 Changed 9 years ago by Malcolm Tredinnick

Cc: Russell Keith-Magee added
Triage Stage: Ready for checkinDesign decision needed

Let's not do this. It introduces "yet another way" to specify tests. Multiple doctests can already be specified via the __tests__ variable, so what we need is a way to identify them. Possibly <app_name>.<test_key> where test_key is the key name in the __tests__ dictionary might be most straightforward here.

Russell probably needs to have some input, too, since I have a recollection he's thought about this in the past.

[Triagers: please use "design decision needed" for these types of tickets, not "ready for checkin", which is for non-controversial, fully complete stuff.]

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

Description: modified (diff)
Patch needs improvement: set
Summary: Allow fine grained tests for doctests (allow splitting into many files)Allow test runner to execute individual doctests
Triage Stage: Design decision neededAccepted

I'm all in favour of the idea of greater granularity for running doctests. However, as Malcolm rightly points out, doctests already provide a multi-file option through the __tests__ dictionary. The Django test runner should supplement, not replace this approach.

Invoking parts of a __tests__ dictionary would certainly be a valuable contribution, but it doesn't completely solve the problem. Doctests can be defined inline on a method or class (the classic sense of a doctest); it would be nice to be able to invoke these individual tests, too.

I'll mark this as accepted, but for the concept, not the provided implementation. I've updated the ticket to better reflect the accepted idea.

comment:6 Changed 9 years ago by David Larlet

Ok, I'll try to do something with __tests__, thanks for your suggestions. Inline doctests looks a bit trickier at first sight.

comment:7 Changed 8 years ago by Adrian Holovaty

Component: ToolsTesting framework

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

Owner: changed from David Larlet to nobody

Reverting to nobody since no progress has been made for a while.

comment:9 Changed 7 years ago by Dan Fairs

Cc: Dan Fairs added

comment:10 Changed 7 years ago by Robin

Cc: Robin added

comment:11 Changed 7 years ago by David Larlet

Cc: David Larlet added

Since [12255], I think this issue should be fixed by a snippet and is not anymore required as a trunk addition. As I understand it, it's now as easy as overriding DjangoTestSuiteRunner.build_suite with a call to doctests or whatever.

comment:12 Changed 7 years ago by Russell Keith-Magee

@david - no this is still a trunk problem. The new class-based structure will make this easier to do as a snippet while you wait for a final patch to hit trunk, but that doesn't remove the need for a solution in trunk.

comment:13 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [12364]) Fixed #6364 -- Added the ability to run individual doctests.

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