diff options
author | Matt Clay <matt@mystile.com> | 2019-08-28 08:40:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-28 08:40:06 +0200 |
commit | f5d829392a17e20d0ba02c30e5a377a43cf70cfd (patch) | |
tree | 6dba1bdf24e10806d8713bfc18b1c7357b4a8ed7 /test/lib/ansible_test/_internal/test.py | |
parent | Adding snapshot module (#61418) (diff) | |
download | ansible-f5d829392a17e20d0ba02c30e5a377a43cf70cfd.tar.xz ansible-f5d829392a17e20d0ba02c30e5a377a43cf70cfd.zip |
Overhaul ansible-test test path handling. (#61416)
* Remove .keep files from test/results/ dirs.
* Remove classification of test/results/ dir.
* Add results_relative to data context.
* Use variables in delegation paths.
* Standardize file writing and results paths.
* Fix issues reported by PyCharm.
* Clean up invocation of coverage command.
It now runs through the injector.
* Hack to allow intercept_command in cover.py.
* Simplify git ignore for test results.
* Use test result tmp dir instead of cache dir.
* Remove old .pytest_cache reference.
* Fix unit test docker delegation.
* Show HTML report link.
* Clean up more results references.
* Move import sanity test output to .tmp dir.
* Exclude test results dir from coverage.
* Fix import sanity test lib paths.
* Fix hard-coded import test paths.
* Fix most hard-coded integration test paths.
* Fix PyCharm warnings.
* Fix import placement.
* Fix integration test dir path.
* Fix Shippable scripts.
* Fix Shippable matrix check.
* Overhaul key pair management.
Diffstat (limited to 'test/lib/ansible_test/_internal/test.py')
-rw-r--r-- | test/lib/ansible_test/_internal/test.py | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/test/lib/ansible_test/_internal/test.py b/test/lib/ansible_test/_internal/test.py index 294ba35388..19c6bb2ca5 100644 --- a/test/lib/ansible_test/_internal/test.py +++ b/test/lib/ansible_test/_internal/test.py @@ -3,23 +3,22 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import datetime -import json import os from . import types as t from .util import ( display, - make_dirs, - to_bytes, ) -from .config import ( - TestConfig, +from .util_common import ( + write_text_test_results, + write_json_test_results, + ResultType, ) -from .data import ( - data_context, +from .config import ( + TestConfig, ) @@ -118,23 +117,22 @@ class TestResult: :type args: TestConfig """ - def create_path(self, directory, extension): + def create_result_name(self, extension): """ - :type directory: str :type extension: str :rtype: str """ - path = os.path.join(data_context().results, directory, 'ansible-test-%s' % self.command) + name = 'ansible-test-%s' % self.command if self.test: - path += '-%s' % self.test + name += '-%s' % self.test if self.python_version: - path += '-python-%s' % self.python_version + name += '-python-%s' % self.python_version - path += extension + name += extension - return path + return name def save_junit(self, args, test_case, properties=None): """ @@ -143,8 +141,6 @@ class TestResult: :type properties: dict[str, str] | None :rtype: str | None """ - path = self.create_path('junit', '.xml') - test_suites = [ self.junit.TestSuite( name='ansible-test', @@ -159,8 +155,7 @@ class TestResult: if args.explain: return - with open(path, 'wb') as xml: - xml.write(to_bytes(report)) + write_text_test_results(ResultType.JUNIT, self.create_result_name('.xml'), report) class TestTimeout(TestResult): @@ -207,10 +202,7 @@ One or more of the following situations may be responsible: </testsuites> ''' % (timestamp, message, output) - path = self.create_path('junit', '.xml') - - with open(path, 'w') as junit_fd: - junit_fd.write(xml.lstrip()) + write_text_test_results(ResultType.JUNIT, self.create_result_name('.xml'), xml.lstrip()) class TestSuccess(TestResult): @@ -335,16 +327,10 @@ class TestFailure(TestResult): ], ) - path = self.create_path('bot', '.json') - if args.explain: return - make_dirs(os.path.dirname(path)) - - with open(path, 'w') as bot_fd: - json.dump(bot_data, bot_fd, indent=4, sort_keys=True) - bot_fd.write('\n') + write_json_test_results(ResultType.BOT, self.create_result_name('.json'), bot_data) def populate_confidence(self, metadata): """ |