From 2f11a8569806933a0e585a576e6e6af652ae6bfb Mon Sep 17 00:00:00 2001 From: Raquel Alegre Date: Tue, 23 Aug 2016 16:41:11 +0100 Subject: [PATCH 1/5] Import pkg_resources only when necessary. --- _pytest/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index 2a121581148..a401bb0688b 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -5,7 +5,6 @@ import types import warnings -import pkg_resources import py # DON't import pytest here because it causes import cycle troubles import sys, os @@ -942,6 +941,7 @@ def _consider_importhook(self, args, entrypoint_name): and find all the installed plugins to mark them for re-writing by the importhook. """ + import pkg_resources ns, unknown_args = self._parser.parse_known_and_unknown_args(args) mode = ns.assertmode if mode == 'rewrite': From 7d498fdc8247ed06c79a0407ddd5fb0f781ce20f Mon Sep 17 00:00:00 2001 From: Raquel Alegre Date: Tue, 23 Aug 2016 16:47:15 +0100 Subject: [PATCH 2/5] Added myself as AUTHOR as requested on PR. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 2e487e77226..895310caa48 100644 --- a/AUTHORS +++ b/AUTHORS @@ -103,6 +103,7 @@ Punyashloka Biswal Quentin Pradet Ralf Schmitt Raphael Pierzina +Raquel Alegre Roberto Polli Romain Dorgueil Roman Bolshakov From a1597aca89aa05e35499ce775f1135ab4be5fed4 Mon Sep 17 00:00:00 2001 From: Raquel Alegre Date: Tue, 23 Aug 2016 16:48:24 +0100 Subject: [PATCH 3/5] Added #1853 to changelog as requested on PR. --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d571a2bf3db..f6f2333140a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,7 +9,7 @@ * Fix loader error when running ``pytest`` embedded in a zipfile. Thanks `@mbachry`_ for the PR. -* +* Fix pkg_resources import error in Jython projects (`#1853`). * From d3f4b3d14ae385526e26b7c74e469584d769f486 Mon Sep 17 00:00:00 2001 From: Raquel Alegre Date: Tue, 23 Aug 2016 16:50:00 +0100 Subject: [PATCH 4/5] mend --- CHANGELOG.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f6f2333140a..6c9aaaffa1a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,8 +8,9 @@ * Fix loader error when running ``pytest`` embedded in a zipfile. Thanks `@mbachry`_ for the PR. - + * Fix pkg_resources import error in Jython projects (`#1853`). + Thanks `@raquel-ucl`_ for the PR. * From 8f516d27fa2c32b9f90e410c0dbacd26117fd873 Mon Sep 17 00:00:00 2001 From: Raquel Alegre Date: Wed, 24 Aug 2016 10:25:01 +0100 Subject: [PATCH 5/5] Moved import pkg_resources to else clause. --- _pytest/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/config.py b/_pytest/config.py index a401bb0688b..8d115ea6530 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -941,7 +941,6 @@ def _consider_importhook(self, args, entrypoint_name): and find all the installed plugins to mark them for re-writing by the importhook. """ - import pkg_resources ns, unknown_args = self._parser.parse_known_and_unknown_args(args) mode = ns.assertmode if mode == 'rewrite': @@ -950,6 +949,7 @@ def _consider_importhook(self, args, entrypoint_name): except SystemError: mode = 'plain' else: + import pkg_resources self.pluginmanager.rewrite_hook = hook for entrypoint in pkg_resources.iter_entry_points('pytest11'): for entry in entrypoint.dist._get_metadata('RECORD'):