Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:44:05+00:00 2026-05-26T04:44:05+00:00

In the doctests of my module I would like to reference my module with

  • 0

In the doctests of my module I would like to reference my module with the full namespace, for example:

  hp.myfunc(1)

And I would like to avoid cluttering the doctests by writing:

  import healpy as hp

in each of the doctests.

if I run doctest.testmod, I know I can use the globs keyword to provide this, while if I run nose, I can use the setup function.

Is there another standard way that could work with both?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:44:06+00:00Added an answer on May 26, 2026 at 4:44 am

    How are you running the doctests (without nose, that is)? If you are cd’d into the package directory when you attempt to run them, you will run into problems (if you are doing a full import, that is).

    I was able to get a simple doctest (with fully-qualified imports) running with both nosetests and the builtin doctest runner. Here’s my setup:

    Project structure:

    .
    └── mypackage
        ├── __init__.py
        └── mod.py
    

    Here are the contents of my ‘mod.py’ file:

    """foo() providing module
    
    Example:
        >>> import mypackage.mod
        >>> mypackage.mod.foo()
        'bar'
    """
    
    def foo():
        return "bar"
    

    from the ‘.’ directory (project root), I can now run tests:

    $ python -m doctest -v mypackage/*.py
    1 items had no tests:
        __init__
    0 tests in 1 items.
    0 passed and 0 failed.
    Test passed.
    Trying:
        import mypackage.mod
    Expecting nothing
    ok
    Trying:
        mypackage.mod.foo()
    Expecting:
        'bar'
    ok
    1 items had no tests:
        mod.foo
    1 items passed all tests:
       2 tests in mod
    2 tests in 2 items.
    2 passed and 0 failed.
    Test passed.
    

    And now the nosetests:

    $ nosetests --with-doctest
    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.008s
    
    OK
    

    If I try to run the doctest from within the ‘mypackage’ directory, I get an error (which is, I suspect, what’s happening in your case).

    Finally, I don’t think this should make a difference, but I’m running Python 2.7.2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a python module and I would like to unit test it. I
I'd like to use doctests to test the presence of certain warnings. For example,
I've got a Python module with docstrings in class methods, and a real-world example
I'm about to begin my third medium-sized project and would like (for the first
I can put python doctests in the bodies of each function, which I sometimes
I'd like to run doctest s for a set of modules (glob: invenio.webtag* )
Today I ran a bunch of doctests using Python 2.6 on a Ubuntu 9.10
A fellow developer on a project I am on believes that doctests are as
I try to use doctest from example from http://docs.python.org/library/doctest.html But when I run python
I'd like to write a doctest like this: >>> print a.string() foo : a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.