7

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?
Gulzar
  • 23,452
  • 27
  • 113
  • 201
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
  • 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

10

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
  • 124,992
  • 159
  • 614
  • 958