Scharron
Scharron

Reputation: 17767

Nose does not run doctests from imported modules

I have a project with a structure like that :

my_project_with_tests/
  project/
    __init__.py
    module.py
  test/
    test.py

module.py contains two doctest'ed functions:

def foo():
  """
  >>> foo()
  1
  """
  return 1

def test_foo_doctest():
    """
    >>> module.foo()
    1
    """
    pass


def bar():
  """
  >>> bar()
  """
  return 1

test.py contains the necessary bits to run tests:

import sys
import os.path
sys.path = [os.path.abspath("../project")] + sys.path


import module


def test_foo():
    assert module.foo() == 1


def test_bar():
    assert module.bar() == 1

I'm currently running my tests using nose with

nosetests                   \
    --all-modules           \
    --traverse-namespace    \
    --with-coverage         \
    --cover-tests           \
    --with-doctest          \
    --where test/

However, it does not run doctests from my project sources directory (but doctests from the test directory are ok, since test_foo_doctest passes).

  1. Is this the good way to call nose ?
  2. How can I run doctests from the project directory
    • using nose
    • without changing the directory structure
    • without running tests in the project directory

Upvotes: 4

Views: 1430

Answers (1)

munk
munk

Reputation: 12983

  1. That's a good way to call nose, but there's a small problem that prevents your doctests from running. See #2

  2. Change --where test/ to --where . assuming you run the command from project/project. That way nose will see the doctests. Right now it's only looking in test/

Upvotes: 2

Related Questions