How to use _add_timed_test method in stestr

Best Python code snippet using stestr_python

test_scheduler.py

Source:test_scheduler.py Github

copy

Full Screen

...16from stestr.repository import memory17from stestr import scheduler18from stestr.tests import base19class TestScheduler(base.TestCase):20 def _add_timed_test(self, id, duration, result):21 start = datetime.datetime.now()22 start = start.replace(tzinfo=iso8601.UTC)23 result.status(test_id=id, test_status='inprogress',24 timestamp=start)25 timestamp = start + datetime.timedelta(seconds=duration)26 result.status(test_id=id, test_status='success',27 timestamp=timestamp)28 def test_partition_tests(self):29 repo = memory.RepositoryFactory().initialise('memory:')30 result = repo.get_inserter()31 result.startTestRun()32 self._add_timed_test("slow", 3, result)33 self._add_timed_test("fast1", 1, result)34 self._add_timed_test("fast2", 1, result)35 result.stopTestRun()36 test_ids = frozenset(['slow', 'fast1', 'fast2', 'unknown1',37 'unknown2', 'unknown3', 'unknown4'])38 partitions = scheduler.partition_tests(test_ids, 2, repo, None)39 self.assertTrue('slow' in partitions[0])40 self.assertFalse('fast1' in partitions[0])41 self.assertFalse('fast2' in partitions[0])42 self.assertFalse('slow' in partitions[1])43 self.assertTrue('fast1' in partitions[1])44 self.assertTrue('fast2' in partitions[1])45 self.assertEqual(3, len(partitions[0]))46 self.assertEqual(4, len(partitions[1]))47 def test_random_partitions(self):48 repo = memory.RepositoryFactory().initialise('memory:')49 test_ids = frozenset(['a_test', 'b_test', 'c_test', 'd_test'])50 random_parts = scheduler.partition_tests(test_ids, 2, repo, None,51 randomize=True)52 # NOTE(masayukig): We can't test this randomness. So just checking53 # what we should get here.54 self.assertEqual(2, len(random_parts))55 self.assertTrue(isinstance(random_parts, list))56 self.assertTrue(isinstance(random_parts[0], list))57 self.assertTrue(isinstance(random_parts[1], list))58 flatten_random_parts = []59 for i, j in random_parts:60 flatten_random_parts.append(i)61 flatten_random_parts.append(j)62 for i in test_ids:63 self.assertIn(i, flatten_random_parts)64 def test_partition_tests_with_zero_duration(self):65 repo = memory.RepositoryFactory().initialise('memory:')66 result = repo.get_inserter()67 result.startTestRun()68 self._add_timed_test("zero1", 0, result)69 self._add_timed_test("zero2", 0, result)70 result.stopTestRun()71 # Partitioning by two should generate two one-entry partitions.72 test_ids = frozenset(['zero1', 'zero2'])73 partitions = scheduler.partition_tests(test_ids, 2, repo, None)74 self.assertEqual(1, len(partitions[0]))75 self.assertEqual(1, len(partitions[1]))76 def test_partition_tests_with_grouping(self):77 repo = memory.RepositoryFactory().initialise('memory:')78 result = repo.get_inserter()79 result.startTestRun()80 self._add_timed_test("TestCase1.slow", 3, result)81 self._add_timed_test("TestCase2.fast1", 1, result)82 self._add_timed_test("TestCase2.fast2", 1, result)83 result.stopTestRun()84 test_ids = frozenset(['TestCase1.slow', 'TestCase1.fast',85 'TestCase1.fast2', 'TestCase2.fast1',86 'TestCase3.test1', 'TestCase3.test2',87 'TestCase2.fast2', 'TestCase4.test',88 'testdir.testfile.TestCase5.test'])89 def group_id(test_id, regex=re.compile('TestCase[0-5]')):90 match = regex.match(test_id)91 if match:92 return match.group(0)93 partitions = scheduler.partition_tests(test_ids, 2, repo, group_id)94 # Timed groups are deterministic:95 self.assertTrue('TestCase2.fast1' in partitions[0])96 self.assertTrue('TestCase2.fast2' in partitions[0])...

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