Debug Mode in "pytest" can be triggered in a few different ways:
1) Your test raises an exception after passing the "--pdb" option to pytest.
2) The moment your test begins after passing the "--trace" option to pytest.
3) Calling "pdb.set_trace()" or "ipdb.set_trace()" from your test after importing "pdb" or "ipdb" respectively. (Python versions 3.7+ and newer can also use the "breakpoint()" method to enter Debug Mode.)
(Note that you may need to add "-s" to your "pytest" run command to allow breakpoints, unless you already have a "pytest.ini" file present with "addops = --capture=no" in it.)
See https://seleniumbase.com/the-ultimate... for the written tutorial.
(Example tests seen here use the SeleniumBase framework for Web-UI testing.)