[pytest-dev] Pytest + Doctest + Tox

holger krekel holger at merlinux.eu
Mon Apr 20 15:58:21 CEST 2015


Hi Sravan,

On Mon, Apr 20, 2015 at 08:59 -0400, Sravan Bhamidipati wrote:
> Hello pytesters,
> 
> I am trying to get guessit <https://github.com/bsravanin/guessit> to adopt
> pytest this month. It uses tox. When I try to run the tests with the
> "--doctest-modules" option, the tests are being discovered as expected, but
> the run fails with the following error:
> 
> ==========================================================================
> > ERRORS
> > ==========================================================================
> > ________________________________________________________________ ERROR
> > collecting setup.py
> > _________________________________________________________________
> > setup.py:109: in <module>
> >     setup(**args)
> > /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py:139:
> > in setup
> >     raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg
> > E   SystemExit: usage: py.test [global_opts] cmd1 [cmd1_opts] [cmd2
> > [cmd2_opts] ...]
> > E      or: py.test --help [cmd1 cmd2 ...]
> > E      or: py.test --help-commands
> > E      or: py.test cmd --help
> > E
> > E   error: option --doctest-modules not recognized
> > =========================================================== 46 passed, 1
> > error in 15.08 seconds
> > ============================================================
> 
> 
> You can checkout this commit
> <https://github.com/bsravanin/guessit/commit/01b0de3bb52a4c8fced49f5feb0c67a906a5aca4>
> to see what's going on. If you need any more information, please let me
> know.

It seems that ``setup.py`` is collected, not protected by 
``if __name__ == "__main__":`` and thus executes during collection
as a side effect of importing it.

You could add the protection which should suffice.
You could also add "--ignore=setup.py" to to the pytest invocation
(possibly also via the "addopts" config variable).

> There is a second problem. When I try to run "py.test --doctest-modules"
> after activating the virtualenv (source .tox/py27/bin/activate, e.g.), the
> doctests are being discovered immediately. But when I try to run them as
> part of the tox command (which runs "python setup.py test" which in turn
> uses a TestCommand to run pytests), the discover of doctests is taking
> about 15s. It would be nice to be able to also fix that.

I suspect that "python setup.py test" somehow ends up traversing way more
directories and files than your pytest invocation, but not sure.  
You could try to specify the particular directories (the package and
the test directories) to avoid traversing too much.

hope it helps,
holger


> 
> I searched StackOverflow, but there're quite a few pytest-doctest questions
> there that have been unanswered, so I'm emailing this list directly.
> 
> Regards,
> Sravan

> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev


-- 
about me:    http://holgerkrekel.net/about-me/
contracting: http://merlinux.eu


More information about the pytest-dev mailing list