Python3 : Running doctests

Trying to run doctest, I get the error :

‘RhinoCodePythonEngineIO’ object has no attribute ‘encoding’

I tried using unicode docstrings but no cigar. Is there a way to hack this without forking doctest?

Hi @capitaine_fred,

What version of Rhino? If Rhino 8, are you using Python2 or Python3?

You might want to post the script, or a small script that can be run by others, that repeat the issue.

– Dale

Hi @dale,

This is Rhino8, python3.

In foo.py i have :

def foo(x):
    """ Increment x.

    >>> foo(1)
    2
    
    >>> foo(42)
    43

    """

    return  x + 1

and in foo_tests.py :

import unittest
import doctest
import inspect

from foo import foo


class Foo_Tests(unittest.TestCase):
    
    def test_foo_0(self):
        result = foo(0)
        expected = 1
        self.assertEqual(result, expected)


    def test_docstring(self):
       mod = inspect.getmodule(foo)
       doctest_results = doctest.testmod(mod)
       assert doctest_results.failed == 0


if __name__ == "__main__":

    suite = unittest.TestLoader().loadTestsFromTestCase(Foo_Tests)
    unittest.TextTestRunner(verbosity=2).run(suite)

Resulting in :

test_docstring (__main__.Foo_Tests) ... ERROR
test_foo_0 (__main__.Foo_Tests) ... ok

======================================================================
ERROR: test_docstring (__main__.Foo_Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "file:///C:/Users/Work/Desktop/Doctests_test/foo_tests.py", line 19, in test_docstring
  File "doctest.py", line 1954, in testmod
  File "doctest.py", line 1450, in run
AttributeError: 'RhinoCodePythonEngineIO' object has no attribute 'encoding'

----------------------------------------------------------------------
Ran 2 tests in 0.015s

FAILED (errors=1)

Fred.