Opened 5 years ago

Closed 5 years ago

#31704 closed Cleanup/optimization (wontfix)

django.test.runner breaks if ipdb or dependencies raise unexpected exceptions

Reported by: John Vandenberg Owned by: John Vandenberg
Component: Testing framework Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

A particular trigger is when run within pytest which by default creates fake stdio handles, and very indirect prompt_toolkit spits the dummy with a io.UnsupportedOperation . ipdb could behave a bit better in this situation, but the buck stops with django . Unless it was explicitly told to use ipdb , it should fallback to pdb in the event of any exception.

Warning: Output is not a terminal (fd=8).
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 459, in _importconftest
    return self._conftestpath2mod[key]
KeyError: PosixPath('/home/jayvdb/projects/django/.../tests/conftest.py')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/input/vt100.py", line 50, in __init__
    stdin.fileno()
  File "/usr/lib/python3.8/site-packages/_pytest/capture.py", line 711, in fileno
    raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")
io.UnsupportedOperation: redirected stdin is pseudofile, has no fileno()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/site-packages/pytest/__main__.py", line 7, in <module>
    raise SystemExit(pytest.main())
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 73, in main
    config = _prepareconfig(args, plugins)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 223, in _prepareconfig
    return pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/lib/python3.8/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 794, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 1000, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 957, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/usr/lib/python3.8/site-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/lib/python3.8/site-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/lib/python3.8/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 857, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 405, in _set_initial_conftests
    self._try_load_conftest(anchor)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 416, in _try_load_conftest
    self._getconftestmodules(x)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 437, in _getconftestmodules
    mod = self._importconftest(conftestpath)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 484, in _importconftest
    self.consider_conftest(mod)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 537, in consider_conftest
    self.register(conftestmodule, name=conftestmodule.__file__)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 350, in register
    self.consider_module(plugin)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 543, in consider_module
    self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 548, in _import_plugin_specs
    self.import_plugin(import_spec)
  File "/usr/lib/python3.8/site-packages/_pytest/config/__init__.py", line 575, in import_plugin
    __import__(importspec)
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/usr/lib/python3.8/site-packages/_pytest/assertion/rewrite.py", line 143, in exec_module
    exec(co, module.__dict__)
  File "/usr/lib/python3.8/site-packages/pytest_djangoapp/plugin.py", line 6, in <module>
    from django.test.runner import DiscoverRunner
  File "/usr/lib/python3.8/site-packages/django/test/runner.py", line 23, in <module>
    import ipdb as pdb
  File "/usr/lib/python3.8/site-packages/ipdb/__init__.py", line 7, in <module>
    from ipdb.__main__ import set_trace, post_mortem, pm, run             # noqa
  File "/usr/lib/python3.8/site-packages/ipdb/__main__.py", line 33, in <module>
    ipapp.initialize(['--no-term-title'])
  File "<decorator-gen-128>", line 2, in initialize
  File "/usr/lib/python3.8/site-packages/traitlets/config/application.py", line 87, in catch_config_error
    return method(app, *args, **kwargs)
  File "/usr/lib/python3.8/site-packages/IPython/terminal/ipapp.py", line 317, in initialize
    self.init_shell()
  File "/usr/lib/python3.8/site-packages/IPython/terminal/ipapp.py", line 331, in init_shell
    self.shell = self.interactive_shell_class.instance(parent=self,
  File "/usr/lib/python3.8/site-packages/traitlets/config/configurable.py", line 412, in instance
    inst = cls(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 525, in __init__
    self.init_prompt_toolkit_cli()
  File "/usr/lib/python3.8/site-packages/IPython/terminal/interactiveshell.py", line 318, in init_prompt_toolkit_cli
    self.pt_app = PromptSession(
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 458, in __init__
    self.app = self._create_application(editing_mode, erase_when_done)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/shortcuts/prompt.py", line 701, in _create_application
    application: Application[_T] = Application(
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/application.py", line 267, in __init__
    self.input = input or session.input
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/application/current.py", line 57, in input
    self._input = create_input()
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/input/defaults.py", line 43, in create_input
    return Vt100Input(stdin)
  File "/usr/lib/python3.8/site-packages/prompt_toolkit/input/vt100.py", line 57, in __init__
    raise io.UnsupportedOperation("Stdin is not a terminal.")
io.UnsupportedOperation: Stdin is not a terminal.

If you suspect this is an IPython 7.15.0 bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org

You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.

Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
    c.Application.verbose_crash=True

Change History (3)

comment:1 by John Vandenberg, 5 years ago

Owner: changed from nobody to John Vandenberg
Status: newassigned

comment:2 by John Vandenberg, 5 years ago

Has patch: set
Type: UncategorizedCleanup/optimization

comment:3 by Mariusz Felisiak, 5 years ago

Has patch: unset
Resolution: wontfix
Status: assignedclosed

Thanks for this ticket, however it's documented that: "If you have it installed, ipdb is used instead", so IMO we shouldn't fallback to pdb in this case. The current logs looks good to me. Django should break if there is any issue in ipdb or its dependencies.

Note: See TracTickets for help on using tickets.
Back to Top