From ab8b2e75a30d34799311bb2b0f85881842c410b9 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 15 Jun 2016 18:10:08 -0700 Subject: [PATCH] Simplify default pytest_runtestloop The inner function and the explanatory comment it makes necessary can all be removed if we switch to an if/else rather than try/except for this condition. Perhaps this bit comes from my fondness for C, but I think I would find this style clearer and easier to understand even if it weren't for the Python 2 quirk that makes the other style require us to add an unnecessary-looking function abstraction. In any case, given that the alternative does require that abstraction this is definitely simpler. --- AUTHORS | 1 + _pytest/main.py | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 28cce969d..f47961bfe 100644 --- a/AUTHORS +++ b/AUTHORS @@ -47,6 +47,7 @@ Floris Bruynooghe Gabriel Reis Georgy Dyuldin Graham Horler +Greg Price Grig Gheorghiu Guido Wesdorp Harald Armin Massa diff --git a/_pytest/main.py b/_pytest/main.py index 4a6c08775..d8d6dc12e 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -136,17 +136,8 @@ def pytest_runtestloop(session): if session.config.option.collectonly: return True - def getnextitem(i): - # this is a function to avoid python2 - # keeping sys.exc_info set when calling into a test - # python2 keeps sys.exc_info till the frame is left - try: - return session.items[i+1] - except IndexError: - return None - for i, item in enumerate(session.items): - nextitem = getnextitem(i) + nextitem = session.items[i+1] if i+1 < len(session.items) else None item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) if session.shouldstop: raise session.Interrupted(session.shouldstop)