Doctests
tryke automatically discovers and runs Python doctests alongside your regular tests. No configuration needed.
How discovery works
tryke's static parser scans docstrings for the >>> prompt marker. Any docstring containing interactive examples is collected as a test. This works at every level:
Module-level
Function-level
def greet(name):
"""
Return a greeting.
>>> greet("world")
'hello, world'
"""
return f"hello, {name}"
Class-level
class Counter:
"""
A simple counter.
>>> c = Counter(0)
>>> c.value
0
"""
def __init__(self, value):
self.value = value
Method-level
class Counter:
def __init__(self, value):
self.value = value
def increment(self):
"""
Increment the counter by one.
>>> c = Counter(0)
>>> c.increment()
>>> c.value
1
"""
self.value += 1
ELLIPSIS support
Doctests run with the ELLIPSIS flag enabled by default. Use ... to match variable output:
def now():
"""
Return the current timestamp.
>>> now() # doctest: +ELLIPSIS
datetime.datetime(...)
"""
import datetime
return datetime.datetime.now()
Running doctests
Doctests are collected automatically with tryke test. They appear in output with a doctest: prefix:
You can filter them like any other test:
Static discovery
Like all tryke test discovery, doctests are found by parsing source files — not by importing modules. This means discovery is fast and side-effect free. See test discovery for details.