[TIP] pytest, setup.py and custom options
sean at seanfisk.com
Wed Nov 27 01:40:02 PST 2013
Sorry I misunderstood your question. You should be able to add
user-passable options to your test command as follows:
# setup.pyfrom setuptools import setupfrom setuptools.command.test
import test as TestCommand
user_options = [
# long option, short option, description
('flakes', None, 'Use pyflakes'),
('coverage', 'C', 'Show coverage statistics'),
self.flakes = False
self.coverage = False
self.test_args = ['tests']
self.test_args += [
'--cov', 'code_directory', '--cov-report', 'term-missing']
self.test_suite = True
This would add the ability to run python setup.py test --flakes or python
setup.py test --coverage. Make sure you change “code_directory” to the
actual directory containing your code.
I don’t know if it’s easy to pass-through options specified by the user on
the command-line, if that’s what you want. You could definitely munge
sys.argv, but at that point I would not use Setuptools’ test facility and
just create your own by intercepting control at the beginning of the
script. In general, I find distutils and Setuptools a little cumbersome in
this area, which is why I use Paver.
Hope this helps!
On Wed, Nov 27, 2013 at 1:35 AM, Daniel Farina <daniel at heroku.com> wrote:
> On Tue, Nov 26, 2013 at 9:12 PM, Sean Fisk <sean at seanfisk.com> wrote:
> > Hi Daniel,
> > The excellent pytest documentation has a section on Setuptools
> > In that example, you would want to write instead:
> > # ...
> > self.test_args = ['--flakes']
> > # ...
> I don't want a static list of these options: I want the user to be
> able to modify them. I want to have the defaults to be sane (I may
> add a few common options) but allow advanced and/or slow use cases
> (like coverage generation) to be added by the user.
> In retrospect, I think I can do this by munging sys.argv before
> setup() is called, but I am wondering if that is among the better
> ways. It seems rather heavyhanded for setuptools to insist to be
> informed a-priori of every single valid option, so I imagine there may
> be another way.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python