Code

Opened 6 years ago

Closed 6 years ago

#7693 closed (invalid)

Different import paths can impact whether doctests are run or not.

Reported by: davenaff Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

My directory structure looks like this:

/appname/models.py
/appname/utils/init.py (empty)
/appname/utils/util1.py

in util1.py, I do this:
from appname.models import Class1, Class2

This import causes the doctests in models.py to not run. If I remove util1.py entirely, the doctests in models.py are run.

I patched this by editing line 895 in root/django/trunk/django/test/_doctest.py
I changed it from:

return module.name == object.module

to

return module.name.find(object.module) >=0

In my example above:
module.name = 'appname.models' and
object.module = 'projectname.appname.models'

I'm selecting 'has patch' and attaching the file, but frankly am not sure if this is the right way to handle this or not.

Attachments (1)

_doctest.py (101.0 KB) - added by davenaff 6 years ago.

Download all attachments as: .zip

Change History (2)

Changed 6 years ago by davenaff

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

There must be something else going on here - you haven't mentioned anything that imports util1.py, so that code won't be imported, and therefore wont be executed. I don't deny you're seeing a problem, but either util1.py isn't the cause, or there is something else going on that your instructions don't cover.

Also - regarding your proposed solution - _doctest.py is a copy of the Python version, provided as a workaround for bugs in older Python versions. Patches proposing fixes to _doctest.py are almost certainly not the right solution to any problem - if they are the solution, they should be submitted upstream to Python itself.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.