How to use get_repo_open method in stestr

Best Python code snippet using stestr_python

history.py

Source:history.py Github

copy

Full Screen

...199 field_names = ('Run ID', 'Passed', 'Runtime', 'Date', 'Metadata')200 else:201 field_names = ('Run ID', 'Passed', 'Runtime', 'Date')202 try:203 repo = util.get_repo_open(repo_url=repo_url)204 except abstract.RepositoryNotFound as e:205 stdout.write(str(e) + '\n')206 return 1207 try:208 run_ids = repo.get_run_ids()209 except KeyError as e:210 stdout.write(str(e) + '\n')211 return 1212 rows = []213 for run_id in run_ids:214 run = repo.get_test_run(run_id)215 stream = run.get_subunit_stream()216 data = _get_run_details(stream, stdout)217 if show_metadata:218 rows.append((run_id, data['passed'], data['runtime'],219 data['start'], run.get_metadata()))220 else:221 rows.append((run_id, data['passed'], data['runtime'],222 data['start']))223 return (field_names, rows)224def history_show(run_id, repo_url=None, subunit_out=False,225 pretty_out=True, color=False, stdout=sys.stdout,226 suppress_attachments=False, all_attachments=False,227 show_binary_attachments=False):228 """Show a run loaded into a repository229 This function will print the results from the last run in the repository230 to STDOUT. It can optionally print the subunit stream for the last run231 to STDOUT if the ``subunit`` option is set to true.232 Note this function depends on the cwd for the repository if `repo_url` is233 not specified it will use the repository located at CWD/.stestr234 :param str run_id: The run id to show235 :param str repo_url: The url of the repository to use.236 :param bool subunit_out: Show output as a subunit stream.237 :param pretty_out: Use the subunit-trace output filter.238 :param color: Enable colorized output with the subunit-trace output filter.239 :param bool subunit: Show output as a subunit stream.240 :param file stdout: The output file to write all output to. By default241 this is sys.stdout242 :param bool suppress_attachments: When set true attachments subunit_trace243 will not print attachments on successful test execution.244 :param bool all_attachments: When set true subunit_trace will print all245 text attachments on successful test execution.246 :param bool show_binary_attachments: When set to true, subunit_trace will247 print binary attachments in addition to text attachments.248 :return return_code: The exit code for the command. 0 for success and > 0249 for failures.250 :rtype: int251 """252 try:253 repo = util.get_repo_open(repo_url=repo_url)254 except abstract.RepositoryNotFound as e:255 stdout.write(str(e) + '\n')256 return 1257 try:258 if run_id:259 run = repo.get_test_run(run_id)260 else:261 run = repo.get_latest_run()262 except KeyError as e:263 stdout.write(str(e) + '\n')264 return 1265 if subunit_out:266 stream = run.get_subunit_stream()267 output.output_stream(stream, output=stdout)268 # Exits 0 if we successfully wrote the stream.269 return 0270 case = run.get_test()271 try:272 if run_id:273 previous_run = int(run_id) - 1274 else:275 previous_run = repo.get_test_run(repo.latest_id() - 1)276 except KeyError:277 previous_run = None278 failed = False279 if not pretty_out:280 output_result = results.CLITestResult(run.get_id, stdout,281 previous_run)282 summary = output_result.get_summary()283 output_result.startTestRun()284 try:285 case.run(output_result)286 finally:287 output_result.stopTestRun()288 failed = not results.wasSuccessful(summary)289 else:290 stream = run.get_subunit_stream()291 failed = subunit_trace.trace(292 stream, stdout, post_fails=True, color=color,293 suppress_attachments=suppress_attachments,294 all_attachments=all_attachments,295 show_binary_attachments=show_binary_attachments)296 if failed:297 return 1298 else:299 return 0300def history_remove(run_id, repo_url=None, stdout=sys.stdout):301 """Remove a run from a repository302 Note this function depends on the cwd for the repository if `repo_url` is303 not specified it will use the repository located at CWD/.stestr304 :param str run_id: The run id to remove from the repository. Also, can be305 set to ``all`` which will remove all runs from the repository.306 :param str repo_url: The url of the repository to use.307 :param file stdout: The output file to write all output to. By default308 this is sys.stdout309 :return return_code: The exit code for the command. 0 for success and > 0310 for failures.311 :rtype: int312 """313 try:314 repo = util.get_repo_open(repo_url=repo_url)315 except abstract.RepositoryNotFound as e:316 stdout.write(str(e) + '\n')317 return 1318 if run_id == 'all':319 try:320 run_ids = repo.get_run_ids()321 except KeyError as e:322 stdout.write(str(e) + '\n')323 return 1324 for run_id in run_ids:325 repo.remove_run_id(run_id)326 else:327 try:328 repo.remove_run_id(run_id)...

Full Screen

Full Screen

util.py

Source:util.py Github

copy

Full Screen

...17 repo_url = os.getcwd()18 else:19 raise TypeError('Unrecognized repository type %s' % repo_type)20 return repo_url21def get_repo_open(repo_type=None, repo_url=None):22 """Return an already initialized repo object given the parameters23 :param str repo_type: DEPRECATED - The repo module to use for the returned24 repo25 :param str repo_url: An optional repo url, if one is not specified the26 default $CWD/.stestr will be used.27 """28 if repo_type is not None:29 msg = ("WARNING: Specifying repository type is deprecated and will be "30 "removed in future release.\n")31 warnings.warn(msg, DeprecationWarning, stacklevel=3)32 else:33 repo_type = 'file'34 repo_module = importlib.import_module('stestr.repository.' + repo_type)35 if not repo_url:...

Full Screen

Full Screen

test_util.py

Source:test_util.py Github

copy

Full Screen

1# Licensed under the Apache License, Version 2.0 (the "License"); you may2# not use this file except in compliance with the License. You may obtain3# a copy of the License at4#5# http://www.apache.org/licenses/LICENSE-2.06#7# Unless required by applicable law or agreed to in writing, software8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the10# License for the specific language governing permissions and limitations11# under the License.12import os13import shutil14import tempfile15from unittest import mock16from stestr.repository import util17from stestr.tests import base18class TestUtil(base.TestCase):19 def setUp(self):20 super().setUp()21 self.temp_dir = tempfile.mkdtemp()22 self.addCleanup(shutil.rmtree, self.temp_dir)23 cwd = os.getcwd()24 os.chdir(self.temp_dir)25 self.temp_dir = os.getcwd()26 self.addCleanup(os.chdir, cwd)27 def test_get_default_url_file(self):28 repo_url = util._get_default_repo_url('file')29 self.assertEqual(self.temp_dir, repo_url)30 def test_get_default_url_invalid_type(self):31 self.assertRaises(TypeError, util._get_default_repo_url,32 'invalid_type')33 @mock.patch('importlib.import_module', side_effect=ImportError)34 def test_non_sql_get_repo_init_no_deps_import_error(self, import_mock):35 self.assertRaises(ImportError, util.get_repo_initialise, 'file')36 @mock.patch('importlib.import_module', side_effect=ImportError)37 def test_non_sql_get_repo_open_no_deps_import_error(self, import_mock):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stestr automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful