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."""