nose, doctest, and module names in subpackages

Discussion in 'Python' started by davidlmontgomery@gmail.com, Sep 6, 2006.

  1. Guest

    I'm trying to use both nosetests and doctest with the tests
    pulled out into a separate file. My problem is that it
    seems that I need to use different import statements
    depending on from where I run the tests.

    Here's my directory structure:
    /dir
    __init__.py
    /sub
    __init__.py
    code_file.py
    test_code_file.py
    tests.txt

    --- code_file.py: ---
    def example_function():
    return 0

    --- test_code_file.py ---
    def run_tests():
    import doctest
    result=doctest.testfile("tests.txt")
    assert result[0] == 0

    if __name__ == "__main__":
    run_tests()

    --- tests.txt ---
    >>> from code_file import example_function


    With this, nosetests works when run from /dir/sub, but
    the import fails if nosetests is run from /dir.

    If I change tests.txt to

    --- tests.txt ---
    >>> from sub.code_file import example_function


    (adding "sub.") then nosetests works from /dir, but not
    from /dir/sub. And in this case "python test_code_file.py"
    fails when run from /dir/sub.

    In general, I would like to run doctests during development
    from the directory where the code lives, leading me to
    prefer "from code_file import", but I would like to run
    nosetests from the top of the tree, leading me to want
    "from sub.code_file import".

    I played around with variations like using doctest.DocFileSuite
    and nosetests' --with-doctest option, but nothing I tried
    helped with the basic issue of the name of the module
    varying depending on the execution directory.

    It seems I'm missing something very basic here. Any tips
    would be much appreciated.

    (I'm running python 2.4.1 and nosetests 0.9.0)

    David
     
    , Sep 6, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Derek Graham

    How do I declare subpackages?

    Derek Graham, Sep 15, 2004, in forum: VHDL
    Replies:
    7
    Views:
    657
    valentin tihomirov
    Sep 18, 2004
  2. R
    Replies:
    1
    Views:
    680
    Thomas Weidenfeller
    Apr 19, 2006
  3. Egil M?ller

    distutils and RPM subpackages

    Egil M?ller, Oct 18, 2004, in forum: Python
    Replies:
    0
    Views:
    324
    Egil M?ller
    Oct 18, 2004
  4. Gary Jefferson

    logging module and doctest

    Gary Jefferson, Jan 25, 2007, in forum: Python
    Replies:
    3
    Views:
    314
    Gary Jefferson
    Jan 25, 2007
  5. Matthew Brett
    Replies:
    4
    Views:
    298
    John Nagle
    Aug 23, 2011
Loading...

Share This Page