Skip to content

Instantly share code, notes, and snippets.

@apahim
Last active March 2, 2018 13:40
Show Gist options
  • Save apahim/7d9aa165e54b6ed43f36542580df46c7 to your computer and use it in GitHub Desktop.
Save apahim/7d9aa165e54b6ed43f36542580df46c7 to your computer and use it in GitHub Desktop.
from avocado import Test
from avocado import skipIf
_SKIP_CONTROL = '/tmp/skip.control'
def _should_i_skip():
try:
with open(_SKIP_CONTROL, 'r') as file_obj:
res = file_obj.read()
if res and int(res):
return True
except:
return False
return False
def _skip_next(skip=True):
with open(_SKIP_CONTROL, 'w') as file_obj:
if skip:
file_obj.write('1')
else:
file_obj.write('0')
class MyTest(Test):
def test_01(self):
_skip_next()
@skipIf(_should_i_skip(), 'Test skipped')
def test_02(self):
pass
def test_03(self):
_skip_next(False)
@skipIf(_should_i_skip(), 'Test skipped')
def test_04(self):
pass
def test_05(self):
_skip_next()
@skipIf(_should_i_skip(), 'Test skipped')
def test_06(self):
pass
@apahim
Copy link
Author

apahim commented Mar 2, 2018

$ avocado run test_skip.py 
JOB ID     : 9e95b49fea341813c824e00be015eb1e16269e78
JOB LOG    : /home/apahim/avocado/job-results/job-2018-03-02T14.39-9e95b49/job.log
 (1/6) test_skip.py:MyTest.test_01: PASS (0.02 s)
 (2/6) test_skip.py:MyTest.test_02: SKIP
 (3/6) test_skip.py:MyTest.test_03: PASS (0.03 s)
 (4/6) test_skip.py:MyTest.test_04: PASS (0.03 s)
 (5/6) test_skip.py:MyTest.test_05: PASS (0.03 s)
 (6/6) test_skip.py:MyTest.test_06: SKIP
RESULTS    : PASS 4 | ERROR 0 | FAIL 0 | SKIP 2 | WARN 0 | INTERRUPT 0 | CANCEL 0
JOB TIME   : 0.60 s
JOB HTML   : /home/apahim/avocado/job-results/job-2018-03-02T14.39-9e95b49/results.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment