bpo-33718: regrtest: use "xxx then yyy" result if re-run (GH-7521) · python/cpython@07aea16 (original) (raw)

`@@ -389,6 +389,7 @@ def parse_executed_tests(self, output):

`

389

389

``

390

390

`def check_executed_tests(self, output, tests, skipped=(), failed=(),

`

391

391

`env_changed=(), omitted=(),

`

``

392

`+

rerun=(),

`

392

393

`randomize=False, interrupted=False,

`

393

394

`fail_env_changed=False):

`

394

395

`if isinstance(tests, str):

`

`@@ -401,6 +402,8 @@ def check_executed_tests(self, output, tests, skipped=(), failed=(),

`

401

402

`env_changed = [env_changed]

`

402

403

`if isinstance(omitted, str):

`

403

404

`omitted = [omitted]

`

``

405

`+

if isinstance(rerun, str):

`

``

406

`+

rerun = [rerun]

`

404

407

``

405

408

`executed = self.parse_executed_tests(output)

`

406

409

`if randomize:

`

`@@ -435,6 +438,14 @@ def list_regex(line_format, tests):

`

435

438

`regex = list_regex('%s test%s omitted', omitted)

`

436

439

`self.check_line(output, regex)

`

437

440

``

``

441

`+

if rerun:

`

``

442

`+

regex = list_regex('%s re-run test%s', rerun)

`

``

443

`+

self.check_line(output, regex)

`

``

444

`+

self.check_line(output, "Re-running failed tests in verbose mode")

`

``

445

`+

for name in rerun:

`

``

446

`+

regex = "Re-running test %r in verbose mode" % name

`

``

447

`+

self.check_line(output, regex)

`

``

448

+

438

449

`good = (len(tests) - len(skipped) - len(failed)

`

439

450

`- len(omitted) - len(env_changed))

`

440

451

`if good:

`

`@@ -446,14 +457,19 @@ def list_regex(line_format, tests):

`

446

457

`if interrupted:

`

447

458

`self.check_line(output, 'Test suite interrupted by signal SIGINT.')

`

448

459

``

``

460

`+

result = []

`

449

461

`if failed:

`

450

``

`-

result = 'FAILURE'

`

451

``

`-

elif interrupted:

`

452

``

`-

result = 'INTERRUPTED'

`

``

462

`+

result.append('FAILURE')

`

453

463

`elif fail_env_changed and env_changed:

`

454

``

`-

result = 'ENV CHANGED'

`

455

``

`-

else:

`

456

``

`-

result = 'SUCCESS'

`

``

464

`+

result.append('ENV CHANGED')

`

``

465

`+

if interrupted:

`

``

466

`+

result.append('INTERRUPTED')

`

``

467

`+

if not result:

`

``

468

`+

result.append('SUCCESS')

`

``

469

`+

result = ', '.join(result)

`

``

470

`+

if rerun:

`

``

471

`+

self.check_line(output, 'Tests result: %s' % result)

`

``

472

`+

result = 'FAILURE then %s' % result

`

457

473

`self.check_line(output, 'Tests result: %s' % result)

`

458

474

``

459

475

`def parse_random_seed(self, output):

`

`@@ -952,6 +968,21 @@ def test_env_changed(self):

`

952

968

`self.check_executed_tests(output, [testname], env_changed=testname,

`

953

969

`fail_env_changed=True)

`

954

970

``

``

971

`+

def test_rerun_fail(self):

`

``

972

`+

code = textwrap.dedent("""

`

``

973

`+

import unittest

`

``

974

+

``

975

`+

class Tests(unittest.TestCase):

`

``

976

`+

def test_bug(self):

`

``

977

`+

test always fail

`

``

978

`+

self.fail("bug")

`

``

979

`+

""")

`

``

980

`+

testname = self.create_test(code=code)

`

``

981

+

``

982

`+

output = self.run_tests("-w", testname, exitcode=2)

`

``

983

`+

self.check_executed_tests(output, [testname],

`

``

984

`+

failed=testname, rerun=testname)

`

``

985

+

955

986

``

956

987

`if name == 'main':

`

957

988

`unittest.main()

`