提交 2b4a61b7 编写于 作者: A Amador Pahim

Deprecate message in self.skip()

self.skip() is to be deprecated. This is the first step, adding a
message to the exception raised by the self.skip() and adjusting the
examples tests accordingly.
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 82d6d05c
......@@ -790,7 +790,9 @@ class Test(unittest.TestCase):
:param message: an optional message that will be recorded in the logs
:type message: str
"""
raise exceptions.TestSetupSkip(message)
dep_msg = "WARNING: self.skip() will be deprecated. " \
"Use 'self.cancel()' or the skip decorators"
raise exceptions.TestSetupSkip("[%s] %s" % (dep_msg, message))
def cancel(self, message=None):
"""
......
......@@ -960,6 +960,10 @@ Avocado offers some options for the test writers to skip a test:
Test ``skip()`` Method
----------------------
.. warning:: `self.skip()` will be deprecated at the end of 2017.
Please adjust your tests to use the `self.cancel()` or the skip
decorators instead.
Using the ``skip()`` method available in the Test API is only allowed
inside the ``setUp()`` method. Calling ``skip()`` from inside the test is not
allowed as, by concept, you cannot skip a test after it's already initiated.
......
......@@ -4,21 +4,22 @@ from avocado import Test
from avocado import main
class SkipOnSetupTest(Test):
class CancelOnSetupTest(Test):
"""
Example test that skips the current test, on the setUp phase.
Example test that cancels the current test, on the setUp phase.
"""
def setUp(self):
"""
This should end with SKIP.
self.skip() is under deprecation process. This should
end with CANCEL instead.
"""
self.skip('This should end with SKIP.')
self.cancel('This should end with CANCEL.')
def test_wont_be_executed(self):
"""
This won't get to be executed, given that setUp calls .skip().
This won't get to be executed, given that setUp calls .cancel().
"""
pass
......
#!/usr/bin/env python
import avocado
class SkipOutsideSetup(avocado.Test):
"""
Test illustrating the behavior of calling skip() outside setUp().
"""
def test(self):
"""
This should end with ERROR.
The method skip() can only be called from inside setUp(). If called
outside of that method, the test status will be marked as ERROR, with
a reason message that asks you to fix your test.
"""
self.skip('Calling skip() outside setUp() will result in ERROR')
if __name__ == "__main__":
avocado.main()
......@@ -442,17 +442,6 @@ class RunnerOperationTest(unittest.TestCase):
int(r['job_id'], 16) # it's an hex number
self.assertEqual(len(r['job_id']), 40)
def test_skip_outside_setup(self):
os.chdir(basedir)
cmd_line = ("./scripts/avocado run --sysinfo=off --job-results-dir %s "
"--json - skip_outside_setup.py" % self.tmpdir)
result = process.run(cmd_line, ignore_status=True)
expected_rc = exit_codes.AVOCADO_TESTS_FAIL
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" % (expected_rc,
result))
self.assertIn('"status": "ERROR"', result.stdout)
def test_early_latest_result(self):
"""
Tests that the `latest` link to the latest job results is created early
......@@ -563,17 +552,17 @@ class RunnerHumanOutputTest(unittest.TestCase):
(expected_rc, result))
self.assertIn('errortest.py:ErrorTest.test: ERROR', result.stdout)
def test_output_skip(self):
def test_output_cancel(self):
os.chdir(basedir)
cmd_line = ('./scripts/avocado run --sysinfo=off --job-results-dir %s '
'skiponsetup.py' % self.tmpdir)
'cancelonsetup.py' % self.tmpdir)
result = process.run(cmd_line, ignore_status=True)
expected_rc = exit_codes.AVOCADO_ALL_OK
self.assertEqual(result.exit_status, expected_rc,
"Avocado did not return rc %d:\n%s" %
(expected_rc, result))
self.assertIn('skiponsetup.py:SkipOnSetupTest.test_wont_be_executed:'
' SKIP', result.stdout)
self.assertIn('PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 1',
result.stdout)
@unittest.skipIf(not GNU_ECHO_BINARY,
'GNU style echo binary not available')
......@@ -604,7 +593,7 @@ class RunnerHumanOutputTest(unittest.TestCase):
def test_replay_skip_skipped(self):
cmd = ("./scripts/avocado run --job-results-dir %s --json - "
"skiponsetup.py" % self.tmpdir)
"cancelonsetup.py" % self.tmpdir)
result = process.run(cmd)
result = json.loads(result.stdout)
jobid = str(result["job_id"])
......@@ -1079,7 +1068,7 @@ class PluginsXunitTest(AbsPluginsTest, unittest.TestCase):
1, 0, 0, 1, 0)
def test_xunit_plugin_skiponsetuptest(self):
self.run_and_check('skiponsetup.py', exit_codes.AVOCADO_ALL_OK,
self.run_and_check('cancelonsetup.py', exit_codes.AVOCADO_ALL_OK,
1, 0, 0, 0, 1)
def test_xunit_plugin_errortest(self):
......@@ -1144,8 +1133,8 @@ class PluginsJSONTest(AbsPluginsTest, unittest.TestCase):
1, 0, 1, 0)
def test_json_plugin_skiponsetuptest(self):
self.run_and_check('skiponsetup.py', exit_codes.AVOCADO_ALL_OK,
1, 0, 0, 1)
self.run_and_check('cancelonsetup.py', exit_codes.AVOCADO_ALL_OK,
1, 0, 0, 0)
def test_json_plugin_errortest(self):
self.run_and_check('errortest.py', exit_codes.AVOCADO_TESTS_FAIL,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册