Solution 1

def small_numbers(fn):
    def wrapped(*args, **kwargs):
        for arg in args:
            if type(arg) in [int, float]:
                if arg > 100:
                    raise ValueError("Only small numbers allowed!")

        return fn(*args, **kwargs)
    return wrapped

Small numbers decorator

Implement a @small_numbers decorator that enforces numeric arguments passed to a function to be less or equal than 100. If any numeric argument is greater than that specified limit, a ValueError should be raised. Example:

@small_numbers
def my_func(number_param, string_param):
  pass

my_func(99, "Hello")  # Works OK!
my_func(101, "Oh no!")  # ValueErrro Raised!

Test Cases

test small numbers raises for big numbers - Run Test

import pytest


def test_small_numbers_raises_for_big_numbers():
    @small_numbers
    def a_testing_function(a, b, c):
        return "You Should never see this!"

    with pytest.raises(ValueError):
        assert a_testing_function(3, 102, "Good?")

test with only one parameter - Run Test

import pytest

def test_with_only_one_parameter():
    @small_numbers
    def a_testing_function(a):
        return "You see me?"

    # Works with a small param
    assert a_testing_function(3) == "You see me?"

    # But fails with a large one:
    with pytest.raises(ValueError):
        assert a_testing_function(105)

test small number allows small numbers - Run Test

def test_small_number_allows_small_numbers():
    @small_numbers
    def a_testing_function(a, b, c):
        return "All good!"

    assert a_testing_function(3, 99, "Good?") == "All good!"
def small_numbers(fn): pass