You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 3.11, subclassing Enumwithout providing a docstring causes tests to be added to a module's doctest suite.
This lengthens test suites
This creates failures if Enum is not provided in the globs argument to doctest test runners
This creates failures if __repr__ is overridden
importrefromenumimportEnumclassMyEnum(Enum):
def__repr__(self):
"""Suppress the trailing colon and integer"""returnre.sub(r': \d+', '', super().__repr__())
classFinalEnum(MyEnum):
MEMBER=1if__name__=="__main__":
importdoctestdoctest.testmod(globs={'MyEnum': MyEnum, 'FinalEnum': FinalEnum})
3.10
$ python3.10 e.py -v
4 items had no tests:
__main__
__main__.FinalEnum
__main__.MyEnum
__main__.MyEnum.__repr__
0 tests in 4 items.
0 passed and 0 failed.
Test passed.
3.11
$ python3.11 e.py
**********************************************************************
File "/Users/.../e.py", line ?, in __main__.FinalEnum
Failed example:
FinalEnum.MEMBER
Expected:
<FinalEnum.MEMBER: 1>
Got:
<FinalEnum.MEMBER>**********************************************************************
File "/Users/.../e.py", line ?, in __main__.FinalEnum
Failed example:
FinalEnum(1)
Expected:
<FinalEnum.MEMBER: 1>
Got:
<FinalEnum.MEMBER>**********************************************************************
File "/Users/.../e.py", line ?, in __main__.FinalEnum
Failed example:
FinalEnum['MEMBER']
Expected:
<FinalEnum.MEMBER: 1>
Got:
<FinalEnum.MEMBER>**********************************************************************
File "/Users/.../e.py", line ?, in __main__.FinalEnum
Failed example:
list(FinalEnum)
Expected:
[<FinalEnum.MEMBER: 1>]
Got:
[<FinalEnum.MEMBER>]
**********************************************************************
File "/Users/.../e.py", line 10, in __main__.MyEnum
Failed example:
class Color(Enum):
RED = 1
BLUE = 2
GREEN = 3
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[0]>", line 1, in<module>
class Color(Enum):
^^^^
NameError: name 'Enum' is not defined
**********************************************************************
File "/Users/.../e.py", line 19, in __main__.MyEnum
Failed example:
Color.RED
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[1]>", line 1, in<module>
Color.RED
^^^^^
NameError: name 'Color' is not defined
**********************************************************************
File "/Users/.../e.py", line 24, in __main__.MyEnum
Failed example:
Color(1)
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[2]>", line 1, in<module>
Color(1)
^^^^^
NameError: name 'Color' is not defined
**********************************************************************
File "/Users/.../e.py", line 29, in __main__.MyEnum
Failed example:
Color['RED']
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[3]>", line 1, in<module>
Color['RED']
^^^^^
NameError: name 'Color' is not defined
**********************************************************************
File "/Users/.../e.py", line 34, in __main__.MyEnum
Failed example:
len(Color)
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[4]>", line 1, in<module>
len(Color)
^^^^^
NameError: name 'Color' is not defined
**********************************************************************
File "/Users/.../e.py", line 37, in __main__.MyEnum
Failed example:
list(Color)
Exception raised:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/doctest.py", line 1350, in __run
exec(compile(example.source, filename, "single",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<doctest __main__.MyEnum[5]>", line 1, in<module>
list(Color)
^^^^^
NameError: name 'Color' is not defined
**********************************************************************
2 items had failures:
4 of 5 in __main__.FinalEnum
6 of 6 in __main__.MyEnum
***Test Failed*** 10 failures.
Your environment
Python 3.11.0b3
cc/ @mscuthbert (FYI: a potential workaround is to add docstrings)
The text was updated successfully, but these errors were encountered:
Bug report
In 3.11, subclassing
Enum
without providing a docstring causes tests to be added to a module's doctest suite.Enum
is not provided in theglobs
argument todoctest
test runners__repr__
is overridden3.10
$ python3.10 e.py -v 4 items had no tests: __main__ __main__.FinalEnum __main__.MyEnum __main__.MyEnum.__repr__ 0 tests in 4 items. 0 passed and 0 failed. Test passed.
3.11
Your environment
Python 3.11.0b3
cc/ @mscuthbert (FYI: a potential workaround is to add docstrings)
The text was updated successfully, but these errors were encountered: