I commonly use the code auto-formatter Black, which has trained me to use double quotes.
It has become "muscle memory" for me to use double quotes.
The default repr for many classes prints from the Python interactive output with single quotes. I know doctest seeks to reproduce the Python interactive output.
Is there some simple way to have doctest match single or double quotes?
I know one option is to make a custom doctest.OutputChecker. I am wondering if there's a simpler option.
Code Sample
from dataclasses import dataclass
@dataclass
class SomeDataClass:
"""Contains a string."""
data: str
def get_some_dataclass(data: str) -> SomeDataClass:
"""Get a data class containing some specified data.
Returns:
Data class containing the data.
Examples:
>>> get_some_dataclass("hi")
SomeDataClass(data="hi")
"""
return SomeDataClass(data=data)
if __name__ == "__main__":
import doctest
doctest.testmod()
Output:
**********************************************************************
File "quote_or_apostrophe.py", line 23, in __main__.get_some_dataclass
Failed example:
get_some_dataclass("hi")
Expected:
SomeDataClass(data="hi")
Got:
SomeDataClass(data='hi')
**********************************************************************
Versions
I invoke doctest via pytest's doctest integration.
python==3.8.2
pytest==5.4.1