I'm cythonizing an existing module with lots of doctests, which would be useful
in catching any errors or changes in behaviour that might result. However, I
have trouble running doctests in a cython-compiled module. The compiled module
offers the usual __doc__ strings (simple example follows below), yet python -m
fails with "No code object available". Is there a trick?

Thanks in advance for any help.

Best regards,
Jon Olav Vik


-bash-3.2$ cat cydoctest.pyx
def pyfun(x):
    """
    >>> pyfun(3)
    6
    """
    return x * 2

-bash-3.2$ rm -rf *.pyc build *.so *.c && python setup.py build_ext --inplace
running build_ext
cythoning cydoctest.pyx to cydoctest.c
building 'cydoctest' extension
creating build
creating build/temp.linux-x86_64-2.5
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-
prototypes -fPIC -I/site/VERSIONS/compython-2.5/Linux/include/python2.5 -c
cydoctest.c -o build/temp.linux-x86_64-2.5/cydoctest.o
gcc -pthread -shared build/temp.linux-x86_64-2.5/cydoctest.o -L/site/VERSIONS/
compython-2.5/Linux/lib -lpython2.5 -o cydoctest.so

-bash-3.2$ python -c "import cydoctest; print cydoctest.pyfun.__doc__; print
cydoctest"
    >>> pyfun(3)
    6
<module 'cydoctest' from 'cydoctest.so'>

-bash-3.2$ python cydoctest.pyx -v
Trying:
    pyfun(3)
Expecting:
    6
ok
1 items had no tests:
    __main__
1 items passed all tests:
   1 tests in __main__.pyfun
1 tests in 2 items.
1 passed and 0 failed.
Test passed.

-bash-3.2$ python -m cydoctest
Traceback (most recent call last):
  File "/site/VERSIONS/compython-2.5/Linux/lib/python2.5/runpy.py", line 90, in
run_module
    raise ImportError("No code object available for " + mod_name)
ImportError: No code object available for cydoctest
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to