#37299: Allow being able to run a specific PW test or class for multiple browsers
-------------------------------------+-------------------------------------
Reporter: Varun Kasyap | Owner: Zubair
Pentamaraju | Hassan
Type: | Status: assigned
Cleanup/optimization |
Component: Testing framework | Version: dev
Severity: Normal | Resolution:
Keywords: Playwright | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by AJ Collins):
== Our debugging process (skip to summary if you want a shorter answer)
We have narrowed down the bug to `test/runner.py` in
`DiscoverRunner.load_tests_for_label` method:
- When running a single test, `tests` is assigned to
`self.test_loader.loadTestsFromName(label)` and returned. This is where it
**doesn't** find additional browsers.
- When running a full test module, `tests` is assigned to
`self.test_loader.discover(start_dir=label, **kwargs)` and returned. This
correctly adds the additional browser tests.
== Single Test (bug case)
We commented out all but one `PlaywrightTests` to make debugging easier.
When `tests = self.test_loader.loadTestsFromName(label)` runs, we get this
debugger output:
{{{
(Pdb) pp tests
<unittest.suite.TestSuite tests=[<admin_changelist.tests.PlaywrightTests
testMethod=test_add_row_selection>]>
}}}
`admin_changelist.tests.PlaywrightTests` is the first browser in the list
to run the tests with
== Full Test Module (happy case)
`tests = self.test_loader.loadTestsFromName(label)` returns no tests, so
`load_tests_for_label` continues, ultimately finding all tests properly
with `self.test_loader.discover`
{{{
(Pdb) pp tests
...<unittest.suite.TestSuite
tests=[<admin_changelist.tests.FirefoxPlaywrightTests
testMethod=test_add_row_selection>]> .. .<unittest.suite.TestSuite
tests=[<admin_changelist.tests.PlaywrightTests
testMethod=test_add_row_selection>]
}}}
== Summary
When you pass two browsers, a second test class with its own methods is
generated, in our case it's called
`admin_changelist.tests.FirefoxPlaywrightTests`. So when you specify a
single test (e.g.
`admin_changelist.tests.PlaywrightTests.test_add_row_selection`) it's only
going to run that one. It will not run the generated one:
`admin_changelist.tests.FirefoxPlaywrightTests.test_add_row_selection`...
A fun discovery is that you technically **can** run the other browser
tests, you just need to specify them as well
{{{
python tests/runtests.py --playwright=chromium,firefox --parallel=1
admin_changelist.tests.PlaywrightTests.test_add_row_selection
admin_changelist.tests.FirefoxPlaywrightTests.test_add_row_selection
--verbosity 2
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/37299#comment:5>