From 56dc01ffe04501089a3228267c60405007ecfa1a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 22 Mar 2019 16:29:02 +0100 Subject: [PATCH] minor: revisit _possibly_invalidate_import_caches --- src/_pytest/pytester.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index bc1405176..f8a79ebc9 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -611,12 +611,10 @@ class Testdir(object): def _possibly_invalidate_import_caches(self): # invalidate caches if we can (py33 and above) try: - import importlib + from importlib import invalidate_caches except ImportError: - pass - else: - if hasattr(importlib, "invalidate_caches"): - importlib.invalidate_caches() + return + invalidate_caches() def mkdir(self, name): """Create a new (sub)directory."""