[TIP] pytest, setup.py and custom options

Sean Fisk sean at seanfisk.com
Tue Nov 26 21:12:11 PST 2013


Hi Daniel,

The excellent pytest documentation has a section on Setuptools
integration<http://pytest.org/latest/goodpractises.html#integration-with-setuptools-test-commands>.
In that example, you would want to write instead:

# ...
self.test_args = ['--flakes']# ...

These arguments get passed to pytest.main(), which is the key to running
pytest through Python.

The one thing I never loved about these plugins (along with the pytest PEP8
plugin) is that they only check files that are discovered. If you want to
check your code as well as your test files, you have to run pytest *on your
source tree too*. That never felt right to me. In addition, I had generated
Python files that I didn’t want to syntax check. My solution was to run
flake8 on all files reported as
tracked<https://github.com/seanfisk/python-project-template/blob/master/pavement.py.tpl#L173>by
my version control system. *[Disclaimer:
self-promotion]* This is integrated into my Python Project
Template<https://github.com/seanfisk/python-project-template>.
It uses Paver instead of Setuptools for calling pytest, so it might be too
heavyweight for your needs.

Either way, I hope this helps!


--
Sean Fisk


On Tue, Nov 26, 2013 at 8:57 PM, Daniel Farina <daniel at heroku.com> wrote:

> Hello,
>
> I would like to support "python setup.py test" to allow people to more
> easily get started with a project I work on.  I use pytest, which
> supports a large collection of options, and my scrying on the Internet
> fails to produce a way to support simply passing these through to
> pytest to interpret.
>
> For example, let's say I normally I run something like this:
>
>     py.test --flakes
>
> This works fine.
>
> But suppose I try to enable precisely this same thing via "python
> setup.py test --flakes", then I receive:
>
> "error: option --flakes not recognized"
>
> It's not entirely clear to me when these option checks occur and how I
> could accept all options and delegate their handling (and error
> messages) to pytest.
>
> Thanks in advance for any advice one can offer.
>
> _______________________________________________
> 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/20131127/30d9438f/attachment.htm>


More information about the testing-in-python mailing list