[TIP] py.test plugin: setuptools problems

holger krekel holger at merlinux.eu
Thu Mar 10 01:00:48 PST 2011

Hi Geoff,

On Thu, Mar 10, 2011 at 09:10 +0100, Geoff Bache wrote:
> Hi Holger,
> > just to be sure I guess you have seen this (?):
> >
> >    http://pytest.org/plugins.html?highlight=pytest11#making-your-plugin-installable-by-others
> Yes, I've been reading there...
> > You could probably just put a conftest.py into your testing directory
> > or into the root directory of your package.  This constitutes a
> > "local" or project-specific plugin and is automatically detected
> > when you run py.test.  No setuptools entry point logic required.
> It's no good putting it in the testing directory, as I want to
> distribute it and make it convenient to use my package from py.test (I
> don't actually use py.test myself, ordinarily). It probably won't be
> if people need to know that they have to copy a conftest.py file to
> their tests before it will work.

> If it's under my package, how will py.test find it? I tried before
> setting the variable "pytest_plugins" in my test but that didn't work.
> The problem is that my plugin adds additional command line options to
> py.test (indeed, that's the point of it) so presumably it's "too late"
> by the time it finds my tests or my package.

So do you want to distribute a package that your users can install
and then write tests that they can run with py.test including using
some additional command line options?

> > And if you then use "py.test --genscript=mypytest" you have a "myptest.py"
> > script that can be used to run the tests without any installation
> > script.
> I didn't understand what this was for. Would I then distribute this
> script and tell people to run it instead of using py.test directly?

It's meant for situations where a developer wants to have a single-script
version of py.test that does not need to be installed through setuptools
but rather can be called e.g. from a repository checkout.

> >> 2) Any guesses why setuptools would be installing every Python file it
> >> could find under the current working directory in this new "egg"? I
> >> have specified "py_modules" to a single file, but still get everything
> >> (basically a duplicate copy of the whole 'real' package).
> >
> > I am not sure i understand.  Are you using the same setup.py
> > for both the plugin and your package?
> No. But they are checked in to the same repository, so the two
> setup.py files are alongside each other in the same location. (I also
> tried having two separate setup(...) calls in the same file)
> >> 3) Is there any way to tell setuptools not to make an egg? Or even to
> >> just create an "entry point" without installing anythiing? All I want
> >> is for my 5 lines of python to appear in a nice simple .py file
> >> somewhere it can be imported :)
> >
> > I pass on that one but maybe it helps if take a look at this small
> > PEP8 verification plugin:
> >
> >    https://bitbucket.org/hpk42/pytest-pep8/src
> >
> > and maybe use it as a skeleton to work for your purposes?
> > (if the conftest.py solution above is somehow not sufficient).
> I've been using pytest-cov as a skeleton and I think I understand how
> to write the plugin. It's making it available that's the hard part...

At this point i think i could help better if i saw some concrete code.
Do you have a repository URL?  If not then let's maybe try to chat
on #pylib or #python-testing on irc.freenode.net to sort out details.

Usually one can do "python setup.py sdist register upload"
and if you have defined a "pytest11" entry point properly and
if you have a "install_requires=['pytest']" entry then 
installing your package should install pytest and integrate
your command line options. But probably you mean something else.


More information about the testing-in-python mailing list