pytest-dev / pytest-timeout

MIT License
216 stars 64 forks source link

Make timeout duration unit self-documenting #80

Open l0b0 opened 3 years ago

l0b0 commented 3 years ago

In a statement like @mark.timeout(50) there is nothing to say the duration is defined in seconds. This has a few disadvantages:

It would be nice if it instead were self-documenting. Some alternatives:

flub commented 1 year ago

I think a PR allowing to use timedelta in there would be acceptable.

s0undt3ch commented 11 months ago

Here's an idea...

marker = item.get_closest_marker(name="timeout")
if marker.args:
    # Old marker
    if len(marker.args) > 1:
        raise RuntimeError("The `timeout` marker only accepts one argument.")
    if marker.kwargs:
        raise RuntimeError("The `timeout` marker does not accept keyword arguments when arguments are passed.")
    timeout = timedelta(seconds=marker.args[0])
elif marker.kwargs:
    timeout = timedelta(**marker.kwargs)
else:
    raise RuntimeError("The `timeout` marker needs either argument or keyword arguments passed.")