New issue 8: pytest-cache plugin not loading when using setuptools integration https://bitbucket.org/hpk42/pytest-cache/issue/8/pytest-cache-plugin-not-loading-when-using
jtriley: The pytest-cache plugin is not being loaded when using pytest's setuptools integration in the case that pytest-cache is not installed into site-packages. In this case pytest-cache gets downloaded and installed to a local egg in the current working directory by setuptools (due to `tests_require=["pytest-cov", "pytest-pep8", "pytest-flakes", "pytest"]`) and I get this error when running `python setup.py test`: ``` $ pip freeze | grep -i pytest # no output here (ie no pytest* in site-packages) $ python setup.py test running test Searching for pytest Reading https://pypi.python.org/simple/pytest/ Best match: pytest 2.5.2 Downloading https://pypi.python.org/packages/source/p/pytest/pytest-2.5.2.tar.gz#md5=8ea3d1939e81514ccba9ba0e9566b5be Processing pytest-2.5.2.tar.gz Writing /tmp/easy_install-odE70G/pytest-2.5.2/setup.cfg Running pytest-2.5.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-odE70G/pytest-2.5.2/egg-dist-tmp-EJlcV7 Installed /repos/starcluster/pytest-2.5.2-py2.6.egg Searching for pytest-flakes Reading https://pypi.python.org/simple/pytest-flakes/ Best match: pytest-flakes 0.2 Downloading https://pypi.python.org/packages/source/p/pytest-flakes/pytest-flakes-0.2.zip#md5=44b8f9746fcd827de5c02f14b01728c1 Processing pytest-flakes-0.2.zip Writing /tmp/easy_install-Va719z/pytest-flakes-0.2/setup.cfg Running pytest-flakes-0.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Va719z/pytest-flakes-0.2/egg-dist-tmp-6BG8vX zip_safe flag not set; analyzing archive contents... Installed /repos/starcluster/pytest_flakes-0.2-py2.6.egg Searching for pytest-pep8 Reading https://pypi.python.org/simple/pytest-pep8/ Best match: pytest-pep8 1.0.5 Downloading https://pypi.python.org/packages/source/p/pytest-pep8/pytest-pep8-1.0.5.tar.gz#md5=6199353734615fde47d1fbfef1ebc737 Processing pytest-pep8-1.0.5.tar.gz Writing /tmp/easy_install-XWWEl7/pytest-pep8-1.0.5/setup.cfg Running pytest-pep8-1.0.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-XWWEl7/pytest-pep8-1.0.5/egg-dist-tmp-yLvZVL warning: no directories found matching 'doc' warning: no directories found matching 'test_pep8.py' zip_safe flag not set; analyzing archive contents... Installed /repos/starcluster/pytest_pep8-1.0.5-py2.6.egg Searching for pytest-cov Reading https://pypi.python.org/simple/pytest-cov/ Best match: pytest-cov 1.6 Downloading https://pypi.python.org/packages/source/p/pytest-cov/pytest-cov-1.6.tar.gz#md5=6da54d74bde9d200de45068ba2ea637a Processing pytest-cov-1.6.tar.gz Writing /tmp/easy_install-KJqVFv/pytest-cov-1.6/setup.cfg Running pytest-cov-1.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-KJqVFv/pytest-cov-1.6/egg-dist-tmp-nVGVAM Installed /repos/starcluster/pytest_cov-1.6-py2.6.egg Searching for pytest-cache Reading https://pypi.python.org/simple/pytest-cache/ Best match: pytest-cache 1.0 Downloading https://pypi.python.org/packages/source/p/pytest-cache/pytest-cache-1.0.tar.gz#md5=e51ff62fec70a1fd456d975ce47977cd Processing pytest-cache-1.0.tar.gz Writing /tmp/easy_install-Rnm1YK/pytest-cache-1.0/setup.cfg Running pytest-cache-1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Rnm1YK/pytest-cache-1.0/egg-dist-tmp-Gorswt zip_safe flag not set; analyzing archive contents... Installed /repos/starcluster/pytest_cache-1.0-py2.6.egg running egg_info writing dependency_links to StarCluster.egg-info/dependency_links.txt writing requirements to StarCluster.egg-info/requires.txt writing StarCluster.egg-info/PKG-INFO writing top-level names to StarCluster.egg-info/top_level.txt writing entry points to StarCluster.egg-info/entry_points.txt reading manifest file 'StarCluster.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching 'requirements.txt' writing manifest file 'StarCluster.egg-info/SOURCES.txt' running build_ext usage: setup.py [options] [file_or_dir] [file_or_dir] [...] setup.py: error: unrecognized arguments: --clearcache ``` If I then install pytest-cache into site-packages the plugin loads as expected: ``` $ rm -rf pytest_cache-1.0-py2.6.egg $ pip install pytest-cache $ python setup.py test running test running egg_info writing dependency_links to StarCluster.egg-info/dependency_links.txt writing requirements to StarCluster.egg-info/requires.txt writing StarCluster.egg-info/PKG-INFO writing top-level names to StarCluster.egg-info/top_level.txt writing entry points to StarCluster.egg-info/entry_points.txt reading manifest file 'StarCluster.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching 'requirements.txt' writing manifest file 'StarCluster.egg-info/SOURCES.txt' running build_ext ========== test session starts ==================== platform linux2 -- Python 2.6.8 -- py-1.4.20 -- pytest-2.5.2 -- /home/user/.virtualenvs/starcluster/bin/python cachedir: /repos/starcluster/.cache plugins: flakes, pep8, cov, cache collected 272 items starcluster/__init__.py:0: PEP8-check PASSED ... ``` To fix this I've applied the following patch to PyTest's run_tests method in order to properly load the cache plugin: ``` class PyTest(TestCommand): ... def run_tests(self): import pytest import _pytest.config pm = _pytest.config.get_plugin_manager() pm.consider_setuptools_entrypoints() errno = pytest.main(self.test_args) sys.exit(errno) ``` Another approach is to simply import the pytest-cache plugin and pass it to pytest.main via the plugins kwarg. The pytest-cache plugin for my project gets pulled in by pytest-pep8. Interestingly if I install pytest and plugins (pytest-cov, pytest-cache, pytest-pep8, and pytest-flakes) to site-packages first and then `pip uninstall pytest-cache` then setuptools will download and install pytest-cache to the current working directory as an egg and the plugin gets loaded: ``` $ pip freeze | grep -i pytest # no pytest* packages installed $ pip install pytest pytest-{cov,pep8,flakes} <<< Downloading/unpacking pytest Using download cache from /home/user/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpytest%2Fpytest-2.5.2.tar.gz Running setup.py (path:/home/user/.virtualenvs/starcluster/build/pytest/setup.py) egg_info for package pytest Downloading/unpacking pytest-cov Using download cache from /home/user/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpytest-cov%2Fpytest-cov-1.6.tar.gz Running setup.py (path:/home/user/.virtualenvs/starcluster/build/pytest-cov/setup.py) egg_info for package pytest-cov Downloading/unpacking pytest-pep8 Using download cache from /home/user/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpytest-pep8%2Fpytest-pep8-1.0.5.tar.gz Running setup.py (path:/home/user/.virtualenvs/starcluster/build/pytest-pep8/setup.py) egg_info for package pytest-pep8 warning: no directories found matching 'doc' warning: no directories found matching 'test_pep8.py' Downloading/unpacking pytest-flakes Using download cache from /home/user/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpytest-flakes%2Fpytest-flakes-0.2.zip Running setup.py (path:/home/user/.virtualenvs/starcluster/build/pytest-flakes/setup.py) egg_info for package pytest-flakes Requirement already satisfied (use --upgrade to upgrade): py>=1.4.20 in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest) Requirement already satisfied (use --upgrade to upgrade): argparse in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest) Requirement already satisfied (use --upgrade to upgrade): cov-core>=1.6 in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest-cov) Downloading/unpacking pytest-cache (from pytest-pep8) Using download cache from /home/user/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fp%2Fpytest-cache%2Fpytest-cache-1.0.tar.gz Running setup.py (path:/home/user/.virtualenvs/starcluster/build/pytest-cache/setup.py) egg_info for package pytest-cache Requirement already satisfied (use --upgrade to upgrade): pep8>=1.3 in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest-pep8) Requirement already satisfied (use --upgrade to upgrade): pyflakes in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest-flakes) Requirement already satisfied (use --upgrade to upgrade): coverage>=3.4 in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from cov-core>=1.6->pytest-cov) Requirement already satisfied (use --upgrade to upgrade): execnet>=1.1.dev1 in /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages (from pytest-cache->pytest-pep8) Installing collected packages: pytest, pytest-cov, pytest-pep8, pytest-flakes, pytest-cache Running setup.py install for pytest Installing py.test script to /home/user/.virtualenvs/starcluster/bin Installing py.test-2.6 script to /home/user/.virtualenvs/starcluster/bin Running setup.py install for pytest-cov Running setup.py install for pytest-pep8 warning: no directories found matching 'doc' warning: no directories found matching 'test_pep8.py' Running setup.py install for pytest-flakes Running setup.py install for pytest-cache Successfully installed pytest pytest-cov pytest-pep8 pytest-flakes pytest-cache Cleaning up... $ pip uninstall pytest-cache Uninstalling pytest-cache: /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages/pytest_cache-1.0-py2.6.egg-info /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages/pytest_cache.py /home/user/.virtualenvs/starcluster/lib/python2.6/site-packages/pytest_cache.pyc Proceed (y/n)? y Successfully uninstalled pytest-cache $ python setup.py test running test Searching for pytest-cache Reading https://pypi.python.org/simple/pytest-cache/ Best match: pytest-cache 1.0 Downloading https://pypi.python.org/packages/source/p/pytest-cache/pytest-cache-1.0.tar.gz#md5=e51ff62fec70a1fd456d975ce47977cd Processing pytest-cache-1.0.tar.gz Writing /tmp/easy_install-VNYw5V/pytest-cache-1.0/setup.cfg Running pytest-cache-1.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-VNYw5V/pytest-cache-1.0/egg-dist-tmp-8eoxLc zip_safe flag not set; analyzing archive contents... Installed /repos/starcluster/pytest_cache-1.0-py2.6.egg running egg_info writing dependency_links to StarCluster.egg-info/dependency_links.txt writing requirements to StarCluster.egg-info/requires.txt writing StarCluster.egg-info/PKG-INFO writing top-level names to StarCluster.egg-info/top_level.txt writing entry points to StarCluster.egg-info/entry_points.txt reading manifest file 'StarCluster.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files found matching 'requirements.txt' writing manifest file 'StarCluster.egg-info/SOURCES.txt' running build_ext =========== test session starts ========== platform linux2 -- Python 2.6.8 -- py-1.4.20 -- pytest-2.5.2 -- /home/user/.virtualenvs/starcluster/bin/python cachedir: /repos/starcluster/.cache plugins: cache, cov, pep8, flakes collected 272 items starcluster/__init__.py:0: pyflakes-check PASSED starcluster/__init__.py:0: PEP8-check PASSED ... ``` So this may be some chicken and egg problem between pep8 and pyflakes installs. I'm happy to provide more details and/or move the issue to another tracker if the problem turns out to really be in the pytest-pep8 plugin. _______________________________________________ Pytest-dev mailing list [email protected] https://mail.python.org/mailman/listinfo/pytest-dev
