Skip to content

Conversation

@asottile
Copy link
Member

Using a hacked up version of pytest this speeds up pytest --help by 26%:

diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py
index 301bdedc..cdde4ab6 100644
--- a/src/_pytest/assertion/rewrite.py
+++ b/src/_pytest/assertion/rewrite.py
@@ -316,6 +316,7 @@ class AssertionRewritingHook(object):
         Ensure package resources can be loaded from this loader. May be called
         multiple times, as the operation is idempotent.
         """
+        return
         try:
             import pkg_resources
 
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index 3943f847..0db4d254 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -14,7 +14,6 @@ import warnings
 
 import py
 import six
-from pkg_resources import parse_version
 from pluggy import HookimplMarker
 from pluggy import HookspecMarker
 from pluggy import PluginManager
@@ -739,6 +738,7 @@ class Config(object):
         modules or packages in the distribution package for
         all pytest plugins.
         """
+        return
         import pkg_resources
 
         self.pluginmanager.rewrite_hook = hook
@@ -814,6 +814,7 @@ class Config(object):
                 raise
 
     def _checkversion(self):
+        return
         import pytest
 
         minver = self.inicfg.get("minversion", None)
diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py
index 14c6e9ab..dfbcb152 100644
--- a/src/_pytest/outcomes.py
+++ b/src/_pytest/outcomes.py
@@ -173,6 +173,7 @@ def importorskip(modname, minversion=None, reason=None):
     verattr = getattr(mod, "__version__", None)
     if minversion is not None:
         try:
+            raise Skipped('wat')
             from pkg_resources import parse_version as pv
         except ImportError:
             raise Skipped(

(Using best of 5)

$ # before
$ time pytest --help > /dev/null

real	0m0.377s
user	0m0.362s
sys	0m0.012s
$ # after
$ time pytest --help > /dev/null

real	0m0.276s
user	0m0.253s
sys	0m0.016s

@nicoddemus
Copy link
Member

nicoddemus commented Feb 12, 2019

This is definitely interesting. 👍

Did you manage to make all tests pass locally for you with your hacked pytest? And what about pytest's own suite?

@asottile
Copy link
Member Author

This is definitely interesting.

Did you manage to make all tests pass locally for you with your hacked pytest?

I didn't try to get the pytest suite working, only had enough time to stub out the other things using pkg_resources. I can take a stab at a full non-hacked working pytest later

@nicoddemus
Copy link
Member

Nice, let's see if we can get rid of pkg_resources then. 👍

It would be a great 0.9 release together with pytest 4.3.

@asottile
Copy link
Member Author

don't ship this just yet, I think importlib-metadata is the better approach than entrypoints -- at least for pytests's sake

@RonnyPfannschmidt RonnyPfannschmidt changed the title Factor out pkg_resources for entrypoints WIP: Factor out pkg_resources for entrypoints Feb 13, 2019
@asottile asottile changed the title WIP: Factor out pkg_resources for entrypoints WIP: Factor out pkg_resources for importlib_metadata Feb 15, 2019
@asottile
Copy link
Member Author

this is blocked on a 0.9 release of importlib-metadata

@asottile asottile closed this Apr 7, 2019
@asottile asottile deleted the factor_out_pkg_resources branch April 7, 2019 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants