Pytest: Deselecting tests

后端 未结 5 873
臣服心动
臣服心动 2021-01-31 07:28

With pytest, one can mark tests using a decorator

@pytest.mark.slow
def some_slow_test():
    pass

Then, from the command line, one can tell py

5条回答
  •  心在旅途
    2021-01-31 08:26

    If you are trying to run the tests from inside a python file, that is, you run your tests by calling

    $ python testfile.py
    

    which has contents

    import pytest
    
    pytest.main()
    

    and you want to know how to pass the CLI flag in to pytest.main, the answer is:

    pytest.main(["-m", "not slow"])
    

    PS - yes, there are legitimate reasons to call tests this way. Pray you never have to learn them.

提交回复
热议问题