• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LostInDarkMath / pedantic-python-decorators / 21837380391

09 Feb 2026 07:17PM UTC coverage: 99.138% (+3.4%) from 95.781%
21837380391

Pull #114

github

LostInDarkMath
migrate from unittest to pytest
Pull Request #114: migrate from unittest to pytest

273 of 274 branches covered (99.64%)

Branch coverage included in aggregate %.

1797 of 1814 relevant lines covered (99.06%)

2.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/pedantic/decorators/fn_deco_does_same_as_function.py
1
import inspect
3✔
2
from functools import wraps
3✔
3
from typing import Any
3✔
4

5
from pedantic.constants import F, ReturnType
3✔
6

7

8
def does_same_as_function(other_func: F) -> F:
3✔
9
    """
10
        Each time the decorated function is executed, the function other_func is also executed and the results
11
        are compared. An AssertionError is raised if the results are not equal.
12

13
        Example:
14

15
        >>> def other_calculation(a, b, c):
16
        ...     return c + b + a
17
        >>> @does_same_as_function(other_calculation)
18
        ... def some_calculation(a, b, c):
19
        ...     return a + b + c
20
        >>> some_calculation(1, 2, 3)
21
        6
22
    """
23

24
    def decorator(decorated_func: F) -> F:
3✔
25
        @wraps(decorated_func)
3✔
26
        def wrapper(*args: Any, **kwargs: Any) -> ReturnType:
3✔
27
            result = decorated_func(*args, **kwargs)
3✔
28
            other = other_func(*args, **kwargs)
3✔
29

30
            if other != result:
3✔
31
                raise AssertionError(f'Different outputs: Function "{decorated_func.__name__}" returns {result} and '
×
32
                                     f'function "{other_func.__name__}" returns {other} for parameters {args} {kwargs}')
33
            return result
3✔
34

35
        @wraps(decorated_func)
3✔
36
        async def async_wrapper(*args: Any, **kwargs: Any) -> ReturnType:
3✔
37
            result = await decorated_func(*args, **kwargs)
3✔
38

39
            if inspect.iscoroutinefunction(other_func):
3✔
40
                other = await other_func(*args, **kwargs)
3✔
41
            else:
42
                other = other_func(*args, **kwargs)
3✔
43

44
            if other != result:
3✔
45
                raise AssertionError(f'Different outputs: Function "{decorated_func.__name__}" returns {result} and '
3✔
46
                                     f'function "{other_func.__name__}" returns {other} for parameters {args} {kwargs}')
47
            return result
3✔
48

49
        if inspect.iscoroutinefunction(decorated_func):
3✔
50
            return async_wrapper
3✔
51
        else:
52
            return wrapper
3✔
53

54
    return decorator
3✔
55

56

57
if __name__ == "__main__":
58
    import doctest
59
    doctest.testmod(verbose=False, optionflags=doctest.ELLIPSIS)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc