[TIP] excluding test modules based on python version

Florian Bruhin me at the-compiler.org
Fri Jul 21 00:07:51 PDT 2017


Hey,

On Fri, Jul 21, 2017 at 07:38:25AM +0100, Chris Withers wrote:
> I'd like to write some tests for a package that I maintain using some Python
> 3 - only syntax, type annotations in this case.
> 
> How can I tell pytest or nose to ignore that file, but only when running
> under Python 2?

With pytest, put something like this in your conftest.py:

    import sys
    
    def pytest_ignore_collect(path):
        if path.basename == 'test_py3.py' and sys.version_info[0] != 3:
            return True

related docs:
https://docs.pytest.org/en/latest/writing_plugins.html#local-conftest-plugins
https://docs.pytest.org/en/latest/writing_plugins.html#_pytest.hookspec.pytest_ignore_collect

As for nose, even the nose docs recommend not using nose anymore ;)
http://nose.readthedocs.io/en/latest/#note-to-users

Florian

-- 
https://www.qutebrowser.org  | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072  | https://the-compiler.org/pubkey.asc
         I love long mails!  | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170721/a38fc7c1/attachment.pgp>


More information about the testing-in-python mailing list