Replace "ipdb" with an upgraded "pdb" debugger
This commit is contained in:
parent
842deb606a
commit
a6822e9388
|
@ -451,7 +451,7 @@ pytest my_first_test.py --demo
|
|||
|
||||
```python
|
||||
import time; time.sleep(5) # Makes the test wait and do nothing for 5 seconds.
|
||||
import ipdb; ipdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pdb; pdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
```
|
||||
|
||||
|
@ -461,7 +461,7 @@ import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continu
|
|||
pytest my_first_test.py --pdb
|
||||
```
|
||||
|
||||
(**``ipdb``** console commands: ``n``, ``c``, ``s`` => ``next``, ``continue``, ``step``).
|
||||
(**``pdb``** console commands: ``n``, ``c``, ``s`` => ``next``, ``continue``, ``step``).
|
||||
|
||||
<a id="pytest_options"></a>
|
||||
🔵 Here are some useful command-line options that come with <code>pytest</code>:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[pytest]
|
||||
|
||||
# Display console output, disable cacheprovider, and have the ipdb debugger replace pdb:
|
||||
addopts = --capture=no -p no:cacheprovider --pdbcls=IPython.terminal.debugger:TerminalPdb
|
||||
# Display console output, disable cacheprovider:
|
||||
addopts = --capture=no -p no:cacheprovider
|
||||
|
||||
# Ignore warnings such as DeprecationWarning and PytestUnknownMarkWarning
|
||||
filterwarnings =
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[pytest]
|
||||
|
||||
# Display console output, disable cacheprovider, and have the ipdb debugger replace pdb:
|
||||
addopts = --capture=no -p no:cacheprovider --pdbcls=IPython.terminal.debugger:TerminalPdb
|
||||
# Display console output, disable cacheprovider:
|
||||
addopts = --capture=no -p no:cacheprovider
|
||||
|
||||
# Ignore warnings such as DeprecationWarning and PytestUnknownMarkWarning
|
||||
filterwarnings =
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[pytest]
|
||||
|
||||
# Display console output, disable cacheprovider, and have the ipdb debugger replace pdb:
|
||||
addopts = --capture=no -p no:cacheprovider --pdbcls=IPython.terminal.debugger:TerminalPdb
|
||||
# Display console output, disable cacheprovider:
|
||||
addopts = --capture=no -p no:cacheprovider
|
||||
|
||||
# Ignore warnings such as DeprecationWarning and PytestUnknownMarkWarning
|
||||
filterwarnings =
|
||||
|
|
|
@ -325,11 +325,11 @@ pytest --collect-only -q
|
|||
```
|
||||
|
||||
您可以在脚本中使用以下内容来帮助您调试问题:
|
||||
(<i>如果使用ipdb,请确保将“-s”添加到命令行选项中,除非已经在pytest.ini中</i>)
|
||||
(<i>如果使用pdb,请确保将“-s”添加到命令行选项中,除非已经在pytest.ini中</i>)
|
||||
|
||||
```python
|
||||
import time; time.sleep(5) # Makes the test wait and do nothing for 5 seconds.
|
||||
import ipdb; ipdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pdb; pdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
```
|
||||
|
||||
|
@ -339,7 +339,7 @@ import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continu
|
|||
pytest my_first_test.py --pdb -s
|
||||
```
|
||||
|
||||
上面的代码将在出现故障时打开浏览器窗口。(ipdb命令:'n', 'c', 's' => next, continue, step)。
|
||||
上面的代码将在出现故障时打开浏览器窗口。(pdb命令:'n', 'c', 's' => next, continue, step)。
|
||||
|
||||
下面是Pytest附带的一些有用的命令行选项:
|
||||
|
||||
|
|
|
@ -250,7 +250,7 @@ You can use the following calls in your scripts to help you debug issues:
|
|||
|
||||
```python
|
||||
import time; time.sleep(5) # Makes the test wait and do nothing for 5 seconds.
|
||||
import ipdb; ipdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pdb; pdb.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
import pytest; pytest.set_trace() # Enter debugging mode. n = next, c = continue, s = step.
|
||||
```
|
||||
|
||||
|
@ -260,7 +260,7 @@ To pause an active test that throws an exception or error, add ``--pdb -s``:
|
|||
pytest my_first_test.py --pdb -s
|
||||
```
|
||||
|
||||
The code above will leave your browser window open in case there's a failure. (ipdb commands: 'c', 's', 'n' => continue, step, next).
|
||||
The code above will leave your browser window open in case there's a failure. (pdb commands: 'c', 's', 'n' => continue, step, next).
|
||||
|
||||
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Combinations of options:</h3>
|
||||
|
||||
|
|
|
@ -26,12 +26,20 @@ sbase mkrec new_test.py --url=wikipedia.org
|
|||
|
||||
pytest new_test.py --rec -q -s --url=wikipedia.org
|
||||
|
||||
> .../SeleniumBase/examples/new_test.py(7)test_recording()
|
||||
5 def test_recording(self):
|
||||
6 if self.recorder_ext and not self.xvfb:
|
||||
----> 7 import ipdb; ipdb.set_trace()
|
||||
>>>>>>>>>>>>>>>>>> PDB set_trace >>>>>>>>>>>>>>>>>
|
||||
|
||||
ipdb> c
|
||||
-> import pdb; pdb.set_trace()
|
||||
> .../YOUR_CURRENT_DIRECTORY/new_test.py(9)
|
||||
|
||||
5 def test_recording(self):
|
||||
6 if self.recorder_ext and not self.xvfb:
|
||||
7 # When you are done recording actions,
|
||||
8 # type "c" and press [ENTER] to continue
|
||||
9 -> import pdb; pdb.set_trace()
|
||||
return None
|
||||
(Pdb++) c
|
||||
|
||||
>>>>>>>>>>>>>>>>>> PDB continue >>>>>>>>>>>>>>>>>>
|
||||
|
||||
>>> RECORDING SAVED as: recordings/new_test_rec.py
|
||||
**************************************************
|
||||
|
@ -71,7 +79,7 @@ The first command creates a boilerplate test with a breakpoint; the second comma
|
|||
⏺️ You can also use the Recorder to add code to an existing test. To do that, you'll first need to create a breakpoint in your code to insert manual browser actions:
|
||||
|
||||
```python
|
||||
import ipdb; ipdb.set_trace()
|
||||
import pdb; pdb.set_trace()
|
||||
```
|
||||
|
||||
Now you'll be able to run your test with ``pytest``, and it will stop at the breakpoint for you to add in actions: (Press ``c`` and ``ENTER`` on the command-line to continue from the breakpoint.)
|
||||
|
@ -80,7 +88,7 @@ Now you'll be able to run your test with ``pytest``, and it will stop at the bre
|
|||
pytest TEST_NAME.py --rec -s
|
||||
```
|
||||
|
||||
⏺️ You can also set a breakpoint at the start of your test by adding ``--trace`` as a ``pytest`` command-line option: (This is useful when running Recorder Mode without any ``ipdb`` breakpoints.)
|
||||
⏺️ You can also set a breakpoint at the start of your test by adding ``--trace`` as a ``pytest`` command-line option: (This is useful when running Recorder Mode without any ``pdb`` breakpoints.)
|
||||
|
||||
```bash
|
||||
pytest TEST_NAME.py --trace --rec -s
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[pytest]
|
||||
|
||||
# Display console output, disable cacheprovider, and have the ipdb debugger replace pdb:
|
||||
addopts = --capture=no -p no:cacheprovider --pdbcls=IPython.terminal.debugger:TerminalPdb
|
||||
# Display console output, disable cacheprovider:
|
||||
addopts = --capture=no -p no:cacheprovider
|
||||
|
||||
# Ignore warnings such as DeprecationWarning and PytestUnknownMarkWarning
|
||||
filterwarnings =
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import collections
|
||||
import pdb
|
||||
import sys
|
||||
from selenium import webdriver
|
||||
from seleniumbase.__version__ import __version__
|
||||
|
@ -14,6 +15,15 @@ from seleniumbase.plugins.sb_manager import SB # noqa
|
|||
from seleniumbase.plugins.driver_manager import Driver # noqa
|
||||
from seleniumbase.plugins.driver_manager import DriverContext # noqa
|
||||
|
||||
if hasattr(pdb, "DefaultConfig"):
|
||||
# Only load pdbpp configuration if pdbpp is installed
|
||||
pdb.DefaultConfig.filename_color = pdb.Color.blue
|
||||
pdb.DefaultConfig.line_number_color = pdb.Color.turquoise
|
||||
pdb.DefaultConfig.show_hidden_frames_count = False
|
||||
pdb.DefaultConfig.disable_pytest_capturing = True
|
||||
pdb.DefaultConfig.enable_hidden_frames = False
|
||||
pdb.DefaultConfig.truncate_long_lines = True
|
||||
pdb.DefaultConfig.sticky_by_default = True
|
||||
if sys.version_info[0] >= 3:
|
||||
from seleniumbase import translate # noqa
|
||||
if sys.version_info >= (3, 7):
|
||||
|
|
|
@ -259,7 +259,7 @@ def show_mkfile_usage():
|
|||
print(" sbase mkfile new_test.py")
|
||||
print(" Options:")
|
||||
print(" -b / --basic (Basic boilerplate / single-line test)")
|
||||
print(" -r / --rec (adds ipdb breakpoint for Recorder Mode)")
|
||||
print(" -r / --rec (add pdb++ breakpoint for Recorder Mode)")
|
||||
print(" Language Options:")
|
||||
print(" --en / --English | --zh / --Chinese")
|
||||
print(" --nl / --Dutch | --fr / --French")
|
||||
|
|
|
@ -123,10 +123,7 @@ def main():
|
|||
|
||||
data = []
|
||||
data.append("[pytest]")
|
||||
data.append(
|
||||
"addopts = --capture=no -p no:cacheprovider "
|
||||
"--pdbcls=IPython.terminal.debugger:TerminalPdb"
|
||||
)
|
||||
data.append("addopts = --capture=no -p no:cacheprovider")
|
||||
data.append("filterwarnings =")
|
||||
data.append(" ignore::pytest.PytestWarning")
|
||||
data.append(" ignore:.*U.*mode is deprecated:DeprecationWarning")
|
||||
|
@ -165,9 +162,6 @@ def main():
|
|||
data.append("[flake8]")
|
||||
data.append("exclude=recordings,temp")
|
||||
data.append("")
|
||||
data.append("[ipdb]")
|
||||
data.append("context=5")
|
||||
data.append("")
|
||||
data.append("[nosetests]")
|
||||
data.append("nocapture=1")
|
||||
data.append("logging-level=INFO")
|
||||
|
|
|
@ -11,7 +11,7 @@ Example:
|
|||
|
||||
Options:
|
||||
-b / --basic (Basic boilerplate / single-line test)
|
||||
-r / --rec (adds ipdb breakpoint for Recorder Mode)
|
||||
-r / --rec (add pdb++ breakpoint for Recorder Mode)
|
||||
|
||||
Language Options:
|
||||
--en / --English | --zh / --Chinese
|
||||
|
@ -46,7 +46,7 @@ def invalid_run_command(msg=None):
|
|||
exp += " sbase mkfile new_test.py\n"
|
||||
exp += " Options:\n"
|
||||
exp += " -b / --basic (Basic boilerplate / single-line test)\n"
|
||||
exp += " -r / --rec (adds ipdb breakpoint for Recorder Mode)\n"
|
||||
exp += " -r / --rec (add pdb++ breakpoint for Recorder Mode)\n"
|
||||
exp += " Language Options:\n"
|
||||
exp += " --en / --English | --zh / --Chinese\n"
|
||||
exp += " --nl / --Dutch | --fr / --French\n"
|
||||
|
@ -232,7 +232,7 @@ def main():
|
|||
data.append(' self.open("%s")' % url)
|
||||
else:
|
||||
data.append(" if self.recorder_ext and not self.xvfb:")
|
||||
data.append(" import ipdb; ipdb.set_trace()")
|
||||
data.append(" import pdb; pdb.set_trace()")
|
||||
if not basic and not recorder:
|
||||
data.append(
|
||||
' self.type("input", "%s")' " # selector, text" % goodbye
|
||||
|
|
|
@ -172,7 +172,9 @@ def main():
|
|||
data.append("class RecorderTests(BaseCase):")
|
||||
data.append(" def test_recording(self):")
|
||||
data.append(" if self.recorder_ext and not self.xvfb:")
|
||||
data.append(" import ipdb; ipdb.set_trace()")
|
||||
data.append(" # When you are done recording actions,")
|
||||
data.append(' # type "c" and press [ENTER] to continue')
|
||||
data.append(" import pdb; pdb.set_trace()")
|
||||
data.append("")
|
||||
file = codecs.open(file_path, "w+", "utf-8")
|
||||
file.writelines("\r\n".join(data))
|
||||
|
|
|
@ -279,7 +279,7 @@ def recorder_still_running():
|
|||
|
||||
def show_still_running_warning():
|
||||
"""Give the user a chance to end the recording safely via the
|
||||
pytest ipdb Debug Mode so that processes such as chromedriver
|
||||
pytest pdb Debug Mode so that processes such as chromedriver
|
||||
and Python don't remain open and hanging in the background."""
|
||||
messagebox.showwarning(
|
||||
"SeleniumBase Recorder: Still Running!",
|
||||
|
|
|
@ -14050,16 +14050,16 @@ class BaseCase(unittest.TestCase):
|
|||
|
||||
def __activate_behave_post_mortem_debug_mode(self):
|
||||
"""Activate Post Mortem Debug Mode for failing tests that use Behave"""
|
||||
import ipdb
|
||||
import pdb
|
||||
|
||||
ipdb.post_mortem(sb_config.behave_step.exc_traceback)
|
||||
pdb.post_mortem(sb_config.behave_step.exc_traceback)
|
||||
# Post Mortem Debug Mode ("behave -D pdb")
|
||||
|
||||
def __activate_debug_mode_in_teardown(self):
|
||||
"""Activate Debug Mode in tearDown() when using "--final-debug"."""
|
||||
import ipdb
|
||||
import pdb
|
||||
|
||||
ipdb.set_trace()
|
||||
pdb.set_trace()
|
||||
# Final Debug Mode ("--final-debug")
|
||||
|
||||
def has_exception(self):
|
||||
|
|
Loading…
Reference in New Issue