diff --git a/avocado/plugins/jsonresult.py b/avocado/plugins/jsonresult.py index a002cbc690de4e650e0a8d922e6a269ab6abbbe5..ca72318e44df4f3ef2cfd2badd09136a16cd2a0d 100644 --- a/avocado/plugins/jsonresult.py +++ b/avocado/plugins/jsonresult.py @@ -93,12 +93,12 @@ class JSON(plugin.Plugin): def configure(self, app_parser, cmd_parser): self.parser = app_parser - self.parser.add_argument('--json', action='store_true', default=False) - self.parser.add_argument('--json-output', default='-', type=str, + self.parser.add_argument('--json', type=str, dest='json_output', - help='the file where the result should be written') + help='Enable JSON output to the file where the result should be written.' + "Use '-' to redirect to the standard output.") self.configured = True def activate(self, app_args): - if app_args.json: + if app_args.json_output: self.parser.set_defaults(json_result=JSONTestResult) diff --git a/avocado/plugins/xunit.py b/avocado/plugins/xunit.py index 68ce45e8b9da616a25e62b14e9f33243c7f76978..2609cd33c13eca2cd8a28d6aa2013b538fbb2abb 100644 --- a/avocado/plugins/xunit.py +++ b/avocado/plugins/xunit.py @@ -229,13 +229,12 @@ class XUnit(plugin.Plugin): def configure(self, app_parser, cmd_parser): self.parser = app_parser - app_parser.add_argument('--xunit', action='store_true') - app_parser.add_argument('--xunit-output', - default='-', type=str, + app_parser.add_argument('--xunit', type=str, dest='xunit_output', - help='the file where the result should be written') + help=('Enable xUnit output to the file where the result should be written.' + "Use '-' to redirect to the standard output.")) self.configured = True def activate(self, app_args): - if app_args.xunit: + if app_args.xunit_output: self.parser.set_defaults(xunit_result=xUnitTestResult) diff --git a/docs/source/OutputPlugins.rst b/docs/source/OutputPlugins.rst index d71ac1667e5de69d0d2f5a60018afb9606c810cf..8135fe7708fe23f22cd5ca536d1767091a4f261c 100644 --- a/docs/source/OutputPlugins.rst +++ b/docs/source/OutputPlugins.rst @@ -18,7 +18,7 @@ avocado is interested in produce are: As an example of human readable output, we have the dots that python unittests print while executing tests:: - $ unittests/avocado/test_unittest.py + $ unittests/avocado/test_unittest.py ss.......... ---------------------------------------------------------------------- Ran 12 tests in 1.243s @@ -53,7 +53,7 @@ automation projects, such as `jenkins `__. If you want to make avocado to generate xunit output in the standard output of the runner, simply use:: - $ scripts/avocado --xunit run "sleeptest failtest synctest" + $ scripts/avocado --xunit - run "sleeptest failtest synctest" @@ -62,6 +62,9 @@ simply use:: +Note the dash `-` in the option `--xunit`, it means that the output +goes through the standard output. + Machine readable output - json ------------------------------ @@ -69,9 +72,12 @@ Machine readable output - json json avocado plugin outputs job information, similarly to the xunit output plugin:: - $ scripts/avocado --json run "sleeptest failtest synctest" + $ scripts/avocado --json - run "sleeptest failtest synctest" {"tests": [{"test": "sleeptest.1", "url": "sleeptest", "status": "PASS", "time": 1.4282619953155518}, {"test": "failtest.1", "url": "failtest", "status": "FAIL", "time": 0.34017300605773926}, {"test": "synctest.1", "url": "synctest", "status": "PASS", "time": 2.109131097793579}], "errors": 0, "skip": 0, "time": 3.87756609916687, "debuglog": "/home/lmr/avocado/logs/run-2014-06-11-01.35.15/debug.log", "pass": 2, "failures": 1, "total": 3} +Note the dash `-` in the option `--json`, it means that the output +goes through the standard output. + Multiple output plugins ----------------------- @@ -79,7 +85,7 @@ You can enable multiple output plugins at once, as long as only one of them uses the standard output. For example, it is fine to use the xunit plugin on stdout and the JSON plugin to output to a file:: - $ scripts/avocado --xunit --json --json-output /tmp/result.json run "sleeptest synctest" + $ scripts/avocado --xunit - --json /tmp/result.json run "sleeptest synctest" @@ -89,10 +95,10 @@ stdout and the JSON plugin to output to a file:: $ cat /tmp/result.json {"tests": [{"test": "sleeptest.1", "url": "sleeptest", "status": "PASS", "time": 1.345332145690918}, {"test": "synctest.1", "url": "synctest", "status": "PASS", "time": 1.8685932159423828}], "errors": 0, "skip": 0, "time": 3.213925361633301, "debuglog": "/home/lmr/avocado/logs/run-2014-06-11-01.49.35/debug.log", "pass": 2, "failures": 0, "total": 2} -But you won't be able to do the same without the --json-output flag passed to +But you won't be able to do the same without the --json flag passed to the program:: - $ scripts/avocado --xunit --json run "sleeptest synctest" + $ scripts/avocado --xunit - --json - run "sleeptest synctest" Avocado could not set --json and --xunit both to output to stdout. Please set the output flag of one of them to a file to avoid conflicts. @@ -106,4 +112,4 @@ you can refer to :mod:`avocado.plugins.xunit`. In a nutshell, you have to implement a class that inherits from :class:`avocado.result.TestResult` and implements all public methods, that perform actions (write to a file/stream) for each test states. You can take a look at :doc:`Plugins` for more info -on how to write plugins. \ No newline at end of file +on how to write plugins. diff --git a/selftests/all/functional/avocado/basic_tests.py b/selftests/all/functional/avocado/basic_tests.py index ca34cba1789f51a57fd8a4014cc761c92d33f162..3930feab484bf9b386e72f536ba7e59c6524fd75 100644 --- a/selftests/all/functional/avocado/basic_tests.py +++ b/selftests/all/functional/avocado/basic_tests.py @@ -72,7 +72,7 @@ class RunnerOperationTest(unittest.TestCase): def test_runner_doublefail(self): os.chdir(basedir) - cmd_line = './scripts/avocado --xunit run doublefail' + cmd_line = './scripts/avocado --xunit - run doublefail' result = process.run(cmd_line, ignore_status=True) output = result.stdout expected_rc = 1 @@ -89,7 +89,7 @@ class RunnerOperationTest(unittest.TestCase): def test_runner_timeout(self): os.chdir(basedir) - cmd_line = './scripts/avocado --xunit run timeouttest' + cmd_line = './scripts/avocado --xunit - run timeouttest' result = process.run(cmd_line, ignore_status=True) output = result.stdout expected_rc = 1 @@ -104,7 +104,7 @@ class RunnerOperationTest(unittest.TestCase): def test_runner_abort(self): os.chdir(basedir) - cmd_line = './scripts/avocado --xunit run abort' + cmd_line = './scripts/avocado --xunit - run abort' result = process.run(cmd_line, ignore_status=True) expected_rc = 1 unexpected_rc = 3 @@ -181,7 +181,7 @@ class PluginsXunitTest(PluginsSysinfoTest): def run_and_check(self, testname, e_rc, e_ntests, e_nerrors, e_nfailures, e_nskip): os.chdir(basedir) - cmd_line = './scripts/avocado --xunit run %s' % testname + cmd_line = './scripts/avocado --xunit - run %s' % testname result = process.run(cmd_line, ignore_status=True) xml_output = result.stdout self.assertEqual(result.exit_status, e_rc, @@ -247,7 +247,7 @@ class PluginsJSONTest(PluginsSysinfoTest): def run_and_check(self, testname, e_rc, e_ntests, e_nerrors, e_nfailures, e_nskip): os.chdir(basedir) - cmd_line = './scripts/avocado --json run --archive %s' % testname + cmd_line = './scripts/avocado --json - run --archive %s' % testname result = process.run(cmd_line, ignore_status=True) json_output = result.stdout self.assertEqual(result.exit_status, e_rc, diff --git a/selftests/all/functional/avocado/output_tests.py b/selftests/all/functional/avocado/output_tests.py index 4bbcab043ed3130f1b8c4bed8c87e497563a56aa..944cc845987b268bbd231f47996e68634293722a 100644 --- a/selftests/all/functional/avocado/output_tests.py +++ b/selftests/all/functional/avocado/output_tests.py @@ -61,7 +61,7 @@ class OutputPluginTest(unittest.TestCase): def test_output_incompatible_setup(self): os.chdir(basedir) - cmd_line = './scripts/avocado --xunit --json run sleeptest' + cmd_line = './scripts/avocado --xunit - --json - run sleeptest' result = process.run(cmd_line, ignore_status=True) expected_rc = 2 output = result.stdout + result.stderr @@ -74,7 +74,7 @@ class OutputPluginTest(unittest.TestCase): def test_output_incompatible_setup_2(self): os.chdir(basedir) - cmd_line = './scripts/avocado --vm --json run sleeptest' + cmd_line = './scripts/avocado --vm --json - run sleeptest' result = process.run(cmd_line, ignore_status=True) expected_rc = 2 output = result.stdout + result.stderr @@ -88,7 +88,7 @@ class OutputPluginTest(unittest.TestCase): def test_output_compatible_setup(self): tmpfile = tempfile.mktemp() os.chdir(basedir) - cmd_line = './scripts/avocado --journal --xunit --xunit-output %s --json run sleeptest' % tmpfile + cmd_line = './scripts/avocado --journal --xunit %s --json - run sleeptest' % tmpfile result = process.run(cmd_line, ignore_status=True) output = result.stdout + result.stderr expected_rc = 0 @@ -108,7 +108,7 @@ class OutputPluginTest(unittest.TestCase): def test_output_compatible_setup_2(self): tmpfile = tempfile.mktemp() os.chdir(basedir) - cmd_line = './scripts/avocado --xunit --json --json-output %s run sleeptest' % tmpfile + cmd_line = './scripts/avocado --xunit - --json %s run sleeptest' % tmpfile result = process.run(cmd_line, ignore_status=True) output = result.stdout + result.stderr expected_rc = 0 @@ -132,7 +132,7 @@ class OutputPluginTest(unittest.TestCase): tmpfile = tempfile.mktemp() tmpfile2 = tempfile.mktemp() os.chdir(basedir) - cmd_line = './scripts/avocado --xunit --xunit-output %s --json --json-output %s run sleeptest' % (tmpfile, tmpfile2) + cmd_line = './scripts/avocado --xunit %s --json %s run sleeptest' % (tmpfile, tmpfile2) result = process.run(cmd_line, ignore_status=True) output = result.stdout + result.stderr expected_rc = 0