When running the piece of Python code that is run by the extension on discovery (from Python extension output) directly.
start
Traceback (most recent call last):
File "/home/jonas/conda/envs/playground/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/jonas/conda/envs/playground/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jonas/.vscode-server/extensions/ms-python.python-2021.9.1191016588/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/jonas/.vscode-server/extensions/ms-python.python-2021.9.1191016588/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
run()
File "/home/jonas/.vscode-server/extensions/ms-python.python-2021.9.1191016588/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "/home/jonas/conda/envs/playground/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/home/jonas/conda/envs/playground/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/home/jonas/conda/envs/playground/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jonas/projects/playground/discovery.py", line 30, in <module>
print(testId.replace(".", ":") + ":" + get_sourceline(tm))
File "/home/jonas/projects/playground/discovery.py", line 5, in get_sourceline
s, n = inspect.getsourcelines(obj)
File "/home/jonas/conda/envs/playground/lib/python3.7/inspect.py", line 955, in getsourcelines
lines, lnum = findsource(object)
File "/home/jonas/conda/envs/playground/lib/python3.7/inspect.py", line 768, in findsource
file = getsourcefile(object)
File "/home/jonas/conda/envs/playground/lib/python3.7/inspect.py", line 684, in getsourcefile
filename = getfile(object)
File "/home/jonas/conda/envs/playground/lib/python3.7/inspect.py", line 666, in getfile
type(object).__name__))
TypeError: module, class, method, function, traceback, frame, or code object was expected, got _TestMethodWrapper
Since the update to v2021.9.1191016588 discovery of unittests fails when
tornado.testing.AsyncTestCaseis used.Environment data
python.languageServersetting: PylanceExpected behaviour
Successful discovery of test cases, similar to how it happens for bare
unittesttests.Actual behaviour
Discovery of unittests fails, and no unittests are reported. This seems to be the case because the
AsyncTestCasewraps test methods into a class_TestMethodWrapperwhich cannot be handled byinspect.getsourcelines(). While this could be fixed intornado, without too much hassle, this does not solve this issue for other test classes which wrap the test methods.Steps to reproduce:
{ "python.testing.unittestArgs": [ "-v", "-s", "./my_package", "-p", "test_*.py" ], }Logs
Output when running the discovery code directly
When running the piece of Python code that is run by the extension on discovery (from Python extension output) directly.
The following exception is raised