When I use the VS Code debugger with Python to stop at some breakpoints, I often write some lines straight in the debug console (use it as interactive Python shell within my program).
The problem is, when I have errors in these lines, when typed from the debug console, I don't see the full Python-style traceback of the error, but only the last line (<Error_type>: ), i.e., without references to code file where the error was raised, the line raised it, and the full stack trace.
Is there any way to configure the VS Code debugger to show the full traceback for errors raised by lines executed from the debugger?
I develop (and debug) on remote machine through ssh.
Example:
I wrote a file named tmp2.py, which contains:
class A:
def __init__(self, val):
print(val)
a = A()
If I put debug point on line 5: print('start'),
and then from the debug console type directly a = A(), I see this one line output:
TypeError: __init__() missing 1 required positional argument: 'val'
but if I run the full program I see the this elaborated output:
Traceback (most recent call last):
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/innereye/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/home/innereye/anaconda2/envs/py3tf2/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/innereye/deeplearning/tmp2.py", line 6, in <module>
a = A()
TypeError: __init__() missing 1 required positional argument: 'val'
which directs me to the actual file and line where the error raises.
I want the debugger to show me the second output also for lines executed directly from the debug console.
Sorry, but it seems like impossibleļ¼ VSCode hasn't provided related configuration. And I consider that's very hard to get what you want, this is because of the debug theory.
Related
Has anyone tried tried to run MassWappalyzer?
From GitHub: **https://github.com/tristanlatr/MassWappalyzer
**
Hi,
I am trying to run MassWappalyzer on my terminal. i have already installed everything and got my MassWappalyzer folder installed, with the script, samples, etc.
However, when I try running the command python3 -m masswappalyzer -i websites.txt -o websites.xlsx
It states this:
Mass Wappalyzer
Using python-Wappalyzer
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/Users/andreualegre/MassWappalyzer/masswappalyzer.py", line 408, in
main()
File "/Users/andreualegre/MassWappalyzer/masswappalyzer.py", line 401, in main
mass_w = MassWappalyzer(urls, **args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/andreualegre/MassWappalyzer/masswappalyzer.py", line 281, in init
self.analyzer = WappalyzerWrapper(
^^^^^^^^^^^^^^^^^^
File "/Users/andreualegre/MassWappalyzer/masswappalyzer.py", line 247, in init
self._analyze = PythonWappalyzer().analyze
^^^^^^^^^^^^^^^^^^
File "/Users/andreualegre/MassWappalyzer/masswappalyzer.py", line 185, in init
self._wappalyzer = self.Wappalyzer.Wappalyzer.latest(update=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Wappalyzer.latest() got an unexpected keyword argument 'update'
Can anyone help me out?
Thank you!
I have already installed everything and tried different ways to run this code. However, couldn't be able to get the solution. I have also asked the dev fro GitHub's, but he haven't answered yet, that's why I am asking here.
I am running a jenkins pipeline for my testing project using ctest, and I want to have a test report for it.
When I try to use junit2html to parse the output of Test.xml, which is generated by ctest, it will throw could not find test suites in results xml error.
Does anyone knows that how this error occurs and how to fix it?
Thanks in advance.
Details
After I generate the test report with ctest:
ctest --no-compress-output -T Test
# generate Testing/<date-time>/Test.xml
Then I want to create a html report by junit2html module :
python3 -m junit2htmlreport Testing/*/Test.xml
It will throw an error :
$ python3 -m junit2htmlreport Testing/20220802-0720/Test.xml test_report.html
Traceback (most recent call last):
File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/__main__.py", line 6, in <module>
runner.start()
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/runner.py", line 103, in start
run(sys.argv[1:])
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/runner.py", line 90, in run
report = parser.Junit(args[0])
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/parser.py", line 340, in __init__
self.process()
File "/var/lib/jenkins/.local/lib/python3.6/site-packages/junit2htmlreport/parser.py", line 376, in process
raise ParserError("could not find test suites in results xml")
junit2htmlreport.parser.ParserError: could not find test suites in results xml
I'm trying to enter (Alt + Windows Key) in a script to my application. I have defined type_keys
def type_keys(string, element):
"""Type a string char by char to Element window"""
for char in string:
element.type_keys(char)
Then calling it during a save here:
# Save
print("Saving")
type_keys("%{VK_LWIN down}", win)
#wait_win_ready(win)
time.sleep(10)
type_keys("1", win)
win.wait("enabled", timeout = REFRESH_TIMEOUT)
I'm getting an error that seems my syntax is incorrect - but not sure how to fix.
Saving
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\pbixrefresher.exe\__main__.py", line 9, in <module>
File "c:\python36\lib\site-packages\pbixrefresher\pbixrefresher.py", line 67, in main
type_keys("%{VK_LWIN down}", win)
File "c:\python36\lib\site-packages\pbixrefresher\pbixrefresher.py", line 13, in type_keys
element.type_keys(char)
File "c:\python36\lib\site-packages\pywinauto\base_wrapper.py", line 971, in type_keys
vk_packet)
File "c:\python36\lib\site-packages\pywinauto\keyboard.py", line 710, in send_keys
vk_packet=vk_packet)
File "c:\python36\lib\site-packages\pywinauto\keyboard.py", line 621, in parse_keys
raise KeySequenceError('`}` not found')
pywinauto.keyboard.KeySequenceError: `}` not found
Hoping for some help on why I'm receiving this error! Thanks for reading.
This is a typo in this line: type_keys("%{VK_LWIN down}", win) which should be element.type_keys("%{VK_LWIN down}")
The problem is that your implementation of type_keys unrolls the sequence to the something like this:
element.type_keys("%")
element.type_keys("{") # fails here, absolutely expected!
element.type_keys("V")
element.type_keys("K")
element.type_keys("_")
element.type_keys("L")
element.type_keys("W")
element.type_keys("I")
element.type_keys("N")
element.type_keys(" ") # it won't be typed without param `with_spaces=True` (default is False)
element.type_keys("d")
element.type_keys("o")
element.type_keys("w")
element.type_keys("n")
element.type_keys("}")
So, I`m comparing some python test frameworks and came across behave. Thought it was interesting and worth a test drive.
Followed the steps on the tutorial, available at:
https://behave.readthedocs.io/en/stable/tutorial.html
When I ran the behave command on Powershell (Win10 and Python 2.7.10), I got the following error:
Exception TypeError: compile() expected string without null bytes
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\behave\__main__.py", line 187, in <module>
sys.exit(main())
File "C:\Python27\lib\site-packages\behave\__main__.py", line 183, in main
return run_behave(config)
File "C:\Python27\lib\site-packages\behave\__main__.py", line 127, in run_behave
failed = runner.run()
File "C:\Python27\lib\site-packages\behave\runner.py", line 804, in run
return self.run_with_paths()
File "C:\Python27\lib\site-packages\behave\runner.py", line 809, in run_with_paths
self.load_step_definitions()
File "C:\Python27\lib\site-packages\behave\runner.py", line 796, in load_step_definitions
load_step_modules(step_paths)
File "C:\Python27\lib\site-packages\behave\runner_util.py", line 412, in load_step_modules
exec_file(os.path.join(path, name), step_module_globals)
File "C:\Python27\lib\site-packages\behave\runner_util.py", line 385, in exec_file
code = compile(f.read(), filename2, "exec", dont_inherit=True)
TypeError: compile() expected string without null bytes
Has anyone encountered this error while trying to run behave? (Found some threads online related mainly to flask issues but I couldn't solve the problem)
Answering my own question here.
It was an encoding problem.
Sublime was saving my files with an encoding different from UTF-8.
File -> Save with Encoding -> UTF-8 did the trick.
I'm relatively new to python and pdb, but I have a lot of experience with gdb.
My problem is that if I set a number of breakpoints in my code at some point I will want to change something and re-run my debug session retaining these break points. However entering "run" in my pdb session cases my session to terminate with the following output
(Pdb) run
Traceback (most recent call last):
File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib64/python2.6/pdb.py", line 1319, in <module>
pdb.main()
File "/usr/lib64/python2.6/pdb.py", line 1312, in main
pdb.interaction(None, t)
File "/usr/lib64/python2.6/pdb.py", line 198, in interaction
self.cmdloop()
File "/usr/lib64/python2.6/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib64/python2.6/pdb.py", line 267, in onecmd
return cmd.Cmd.onecmd(self, line)
File "/usr/lib64/python2.6/cmd.py", line 219, in onecmd
return func(arg)
File "/usr/lib64/python2.6/pdb.py", line 661, in do_run
raise Restart
pdb.Restart
]$
I've tried this on two independent linux platforms and had the same result but I cannot find any corrections in the documentation.
So if anyone cares the problem was that "run" in pdb is not the exact same as "run" in gdb. In gdb if I enter run the program restarts and continues to the first break point. In pdb the program restarts and goes to the start of the file. I then have to press 'n' followed by 'c' to get to the first break point. If, attempting to get the program to run, I type run a second time at the start of the file the debugger crashes, as shown above.
Here is my file test.py:
import pdb
pdb.set_trace()
print('1 line')
I get the same error when I using command 'python3 test.py':
> /home/wangpq/program_note/test.py(3)<module>()
-> print('1 line')
(Pdb) run
Traceback (most recent call last):
File "program_note/test.py", line 3, in <module>
print('1 line')
File "program_note/test.py", line 3, in <module>
print('1 line')
File "/usr/lib/python3.5/bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python3.5/bdb.py", line 66, in dispatch_line
self.user_line(frame)
File "/usr/lib/python3.5/pdb.py", line 259, in user_line
self.interaction(frame, None)
File "/usr/lib/python3.5/pdb.py", line 346, in interaction
self._cmdloop()
File "/usr/lib/python3.5/pdb.py", line 319, in _cmdloop
self.cmdloop()
File "/usr/lib/python3.5/cmd.py", line 138, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python3.5/pdb.py", line 412, in onecmd
return cmd.Cmd.onecmd(self, line)
File "/usr/lib/python3.5/cmd.py", line 217, in onecmd
return func(arg)
File "/usr/lib/python3.5/pdb.py", line 1022, in do_run
raise Restart
pdb.Restart
Then I use command 'python3 -m pdb test.py'
wangpq#wangpq:~$ python3 -m pdb program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb) restart
Restarting program_note/test.py with arguments:
program_note/test.py
> /home/wangpq/program_note/test.py(1)<module>()
-> import pdb
(Pdb)
It works. So far, I am not sure why this happens.
Upon encountering an abnormal condition (i.e., a bug in your program), pdb rather helpfully says:
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
Here, typing "run" or "restart" will cause the pdb process to unceremoniously terminate as OP states (but "cont" or "step" will restart as promised).
Presumably many impatient pythonistas would rather "run" or "restart" work regardless of whether we've entered "post mortem debugging" but I'm sure the existing restart semantics is the byproduct of a cleaner implementation.