[TIP] Setuptools and pytest integration issue

Eric Larson eric at ionrock.org
Fri Sep 5 09:12:55 PDT 2014


On Sep 5, 2014 8:22 AM, "Laszlo Papp" <lpapp at kde.org> wrote:
>
> It seems that the fix in the documentation is this:
>
>      def initialize_options(self):
>          TestCommand.initialize_options(self)
> -        self.pytest_args = None
> +        self.pytest_args = []
>
>      def finalize_options(self):
>          TestCommand.finalize_options(self)
>
> Setuptools, at least the latest, does not quite work the way that the
> documentation expects it to.
>
>

There is also pytest runner.

https://pypi.python.org/pypi/pytest-runner

My only complaint is that it installs pytest with an egg in the local
directory. That can make it easy to miss dependencies at times because they
may exist in the directory but not in the venv. I think that is a
setuptools pattern. It is not a huge deal, but it helps to be aware of it.

HTH

Eric

> On Mon, Sep 1, 2014 at 5:48 PM, Laszlo Papp <lpapp at kde.org> wrote:
> > Hi all,
> >
> > I am having some issues with getting it working correctly.
> >
> > sudo python setup.py test
> > running test
> > running egg_info
> > writing PyFoo.egg-info/PKG-INFO
> > writing top-level names to PyFoo.egg-info/top_level.txt
> > writing dependency_links to PyFoo.egg-info/dependency_links.txt
> > reading manifest file 'PyFoo.egg-info/SOURCES.txt'
> > writing manifest file 'PyFoo.egg-info/SOURCES.txt'
> > running build_ext
> >
==============================================================================================================================
> > test session starts
> >
===============================================================================================================================
> > platform linux2 -- Python 2.7.8 -- py-1.4.23 -- pytest-2.6.1
> > ERROR: file not found: test
> >
> >
================================================================================================================================
> >  in 0.00 seconds
> >
================================================================================================================================
> >
> > This is the setup.py content that I pretty much copied and pasted over
> > from the official documentation (*):
> >
> > import os
> > import sys
> >
> > from setuptools.command.test import test as TestCommand
> > from setuptools import setup
> >
> > scriptDirectoryPath = os.path.dirname(os.path.realpath(__file__))
> >
> > exec(open(os.path.join(scriptDirectoryPath, 'pyfoo',
'version.py')).read())
> >
> > class PyTest(TestCommand):
> >     user_options = [('pytest-args=', 'a', "Arguments to pass to
py.test")]
> >
> >     def initialize_options(self):
> >         TestCommand.initialize_options(self)
> >         self.pytest_args = None
> >
> >     def finalize_options(self):
> >         TestCommand.finalize_options(self)
> >         self.test_args = []
> >         self.test_suite = True
> >
> >     def run_tests(self):
> >         #import here, cause outside the eggs aren't loaded
> >         import pytest
> >         errno = pytest.main(self.pytest_args)
> >         sys.exit(errno)
> >
> > setup(
> >     name='PyFoo',
> >     version=__version__,
> >     long_description=__doc__,
> >     author='Laszlo Papp',
> >     author_email='laszlo.papp at foo.com',
> >     description = ("Python API for Foo."),
> >     url = "http://www.foo.com",
> >     packages=['pyfoo'],
> >     include_package_data=True,
> >     zip_safe=False,
> >     tests_require=['pytest'],
> >     cmdclass = {'test': PyTest},
> > )
> >
> > If I pass the "tests" directory to pytest as it can be seen below,
> > then it works. However, this is neither mentioned in the official
> > documentation, nor is it something that I would prefer the users to
> > do.
> >
> > python setup.py test --pytest-args=tests
> >
> > Is there a way to just get it automagically working? If yes, is there
> > something missing from the documentation or I have just overlooked
> > something simple? Thanks in advance.
> >
> > Cheers, L.
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140905/a818681a/attachment.htm>


More information about the testing-in-python mailing list