4

I usually run my tests with tox which calls pytest. This setup works fine in many projects. In some projects, however, I have some tests which take long (several minutes). I don't want to run them every time. I would like to decorate the tests as long.

Something like this:

$ tox --skip-long

and

# core modules
import unittest

class Foo(unittest.TestCase):

    def test_bar(self):
        ...

    @long
    def test_long_bar(self):
        ...

How can I do this?
Martin Thoma
  • 108,021
  • 142
  • 552
  • 849
  • A related question is how to skip tests if they are taking too long: https://stackoverflow.com/questions/19527320/how-can-i-limit-the-maximum-running-time-for-a-unit-test – shaneb Jun 16 '20 at 13:42

1 Answers1

7

I found half of the answer here:

@pytest.mark.long

and execute

pytest -v -m "not long"

To run it on tox (source):

tox -- -m "not long"

The output then looks like this:

============================ 2 tests deselected ==================================
========== 20 passed, 2 deselected, 7 warnings in 151.93 seconds =================
Martin Thoma
  • 108,021
  • 142
  • 552
  • 849
  • Thanks! Works out of the box for me, though I also followed the documentation's suggestion to register the mark in `pytest.ini` or `pyproject.toml`: https://docs.pytest.org/en/stable/mark.html – Jason R Stevens CFA Aug 24 '20 at 16:26