2021年2月19日 星期五

[ Python 常見問題 ] How do I disable a test using pytest?

 Source From Here

Question
Let's say I have a bunch of tests:
  1. def test_func_one():  
  2.     ...  
  3.   
  4. def test_func_two():  
  5.     ...  
  6.   
  7. def test_func_three():  
  8.     ...  
Is there a decorator or something similar that I could add to the functions to prevent Pytest from running just that test? The result might look something like:
  1. @pytest.disable()  
  2. def test_func_one():  
  3.     ...  
  4.   
  5. def test_func_two():  
  6.     ...  
  7.   
  8. def test_func_three():  
  9.     ...  
HowTo
Pytest has the skip and skipif decorators, similar to the Python unittest module (which uses skip and skipIf), which can be found in the documentation here.

Examples from the link can be found here:
  1. @pytest.mark.skip(reason="no way of currently testing this")  
  2. def test_the_unknown():  
  3.     ...  
  4.   
  5. import sys  
  6. @pytest.mark.skipif(sys.version_info < (3,3),  
  7.                     reason="requires python3.3")  
  8. def test_function():  
  9.     ...  
The first example always skips the test, the second example allows you to conditionally skip tests.

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...