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 i have :

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

    >>> foo(1)
    >>> foo(42)


    return  x + 1

and in :

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)

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/", line 19, in test_docstring
  File "", line 1954, in testmod
  File "", line 1450, in run
AttributeError: 'RhinoCodePythonEngineIO' object has no attribute 'encoding'

Ran 2 tests in 0.015s

FAILED (errors=1)