Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.4.0 regression for pdbcls #5039

Closed
JBKahn opened this Issue Apr 3, 2019 · 16 comments

Comments

Projects
None yet
2 participants
@JBKahn
Copy link

JBKahn commented Apr 3, 2019

In my code I'm trying to define my own debugger class, which in this case is a bit of a hack to use ipdb I have a file with:

class Debugger(object):
    quitting = None

    def set_trace(self, frame):
        import ipdb  # noqa

        return ipdb.set_trace(frame)  # noqa

    def reset(self, *args, **kwargs):
        from ipdb.__main__ import _init_pdb

        pdb_obj = _init_pdb()
        pdb_obj.botframe = None  # not sure. exception otherwise at quit
        return pdb_obj.reset(*args, **kwargs)

    def interaction(self, *args, **kwargs):
        from ipdb.__main__ import _init_pdb

        pdb_obj = _init_pdb()
        pdb_obj.botframe = None  # not sure. exception otherwise at quit
        return pdb_obj.interaction(*args, **kwargs)

The code is now unable to import any class in my codebase at that step. I just get No module name X for every module in my local repository.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

What --pdbcls setting are you using?
What is the actual error?
Is it with --pdb or pdb.set_trace?

@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

Here is the stacktrace for 4.3.1

> /usr/local/lib/python3.6/site-packages/_pytest/debugging.py(41)pytest_configure()
-> __import__(modname)
(Pdb) l
 36
 37  	def pytest_configure(config):
 38  	    if config.getvalue("usepdb_cls"):
 39  	        modname, classname = config.getvalue("usepdb_cls").split(":")
 40  	        import pdb; pdb.set_trace()
 41  ->	        __import__(modname)
 42  	        pdb_cls = getattr(sys.modules[modname], classname)
 43  	    else:
 44  	        pdb_cls = pdb.Pdb
 45
 46  	    if config.getvalue("trace"):
(Pdb) w
  /usr/local/bin/pytest(11)<module>()
-> sys.exit(main())
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(79)main()
-> return config.hook.pytest_cmdline_main(config=config)
  /usr/local/lib/python3.6/site-packages/pluggy/hooks.py(289)__call__()
-> return self._hookexec(self, self.get_hookimpls(), kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(68)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(62)<lambda>()
-> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  /usr/local/lib/python3.6/site-packages/pluggy/callers.py(187)_multicall()
-> res = hook_impl.function(*args)
  /usr/local/lib/python3.6/site-packages/_pytest/main.py(242)pytest_cmdline_main()
-> return wrap_session(config, _main)
  /usr/local/lib/python3.6/site-packages/_pytest/main.py(205)wrap_session()
-> config._do_configure()
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(638)_do_configure()
-> self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
  /usr/local/lib/python3.6/site-packages/pluggy/hooks.py(311)call_historic()
-> res = self._hookexec(self, self.get_hookimpls(), kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(68)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(62)<lambda>()
-> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  /usr/local/lib/python3.6/site-packages/pluggy/callers.py(187)_multicall()
-> res = hook_impl.function(*args)
> /usr/local/lib/python3.6/site-packages/_pytest/debugging.py(41)pytest_configure()
-> __import__(modname)
(Pdb) import common
(Pdb) from common.debugger import Debugger
(Pdb) Debugger
<class 'common.debugger.Debugger'>
@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

On 4.4.0

/app/nextaccounting # pytest -s journal_entry/tests/test_constants.py
> /usr/local/lib/python3.6/site-packages/_pytest/debugging.py(25)_validate_usepdb_cls()
-> __import__(modname)
(Pdb) w
  /usr/local/bin/pytest(11)<module>()
-> sys.exit(main())
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(60)main()
-> config = _prepareconfig(args, plugins)
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(201)_prepareconfig()
-> pluginmanager=pluginmanager, args=args
  /usr/local/lib/python3.6/site-packages/pluggy/hooks.py(289)__call__()
-> return self._hookexec(self, self.get_hookimpls(), kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(68)_hookexec()
-> return self._inner_hookexec(hook, methods, kwargs)
  /usr/local/lib/python3.6/site-packages/pluggy/manager.py(62)<lambda>()
-> firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  /usr/local/lib/python3.6/site-packages/pluggy/callers.py(187)_multicall()
-> res = hook_impl.function(*args)
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(679)pytest_cmdline_parse()
-> self.parse(args)
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(896)parse()
-> self._preparse(args, addopts=addopts)
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(832)_preparse()
-> self._validate_args(self.getini("addopts"), "via addopts config") + args
  /usr/local/lib/python3.6/site-packages/_pytest/config/__init__.py(814)_validate_args()
-> args, namespace=copy.copy(self.option)
  /usr/local/lib/python3.6/site-packages/_pytest/config/argparsing.py(117)parse_known_and_unknown_args()
-> return optparser.parse_known_args(args, namespace=namespace)
  /usr/local/lib/python3.6/argparse.py(1766)parse_known_args()
-> namespace, args = self._parse_known_args(args, namespace)
  /usr/local/lib/python3.6/argparse.py(1972)_parse_known_args()
-> start_index = consume_optional(start_index)
  /usr/local/lib/python3.6/argparse.py(1912)consume_optional()
-> take_action(action, args, option_string)
  /usr/local/lib/python3.6/argparse.py(1824)take_action()
-> argument_values = self._get_values(action, argument_strings)
  /usr/local/lib/python3.6/argparse.py(2265)_get_values()
-> value = self._get_value(action, arg_string)
  /usr/local/lib/python3.6/argparse.py(2294)_get_value()
-> result = type_func(arg_string)
> /usr/local/lib/python3.6/site-packages/_pytest/debugging.py(25)_validate_usepdb_cls()
-> __import__(modname)
(Pdb) import common
*** ModuleNotFoundError: No module named 'common'
(Pdb) from common.debugger import Debugger
*** ModuleNotFoundError: No module named 'common'
@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

And my setting is --pdbcls=common.debugger:Debugger

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

Just tried --pdbcls ipdb:__main__.debugger_cls and that appears to work already.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

The problem with 4.4.0 appears to be that it stops in _validate_usepdb_cls, i.e. there might be an issue with regard to passed frame offsets, or that tracing is enabled too early already.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

The question about invoking remains: is this due to using set_trace yourself, or via an exception and using --pdb? - I wonder why you are at pytest_configure in the first example already.

@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

I'm using set_trace myself, I just put a breakpoint in to illustrate that it breaks during setup, before it runs any tests. the import fails.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

Ah, ok - likely caused by 84555c8 then.

Anyway, does using ipdb:__main__.debugger_cls work for you, too?

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

The reason is likely that validation gets done now earlier, and your sys.path might not be modified by then already.

@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

Yeah, that should do the trick. IF I did want to extend the debugger class in any way, not being able to load a local module isn't the best. It's a regression albeit not one that affects me.

Yeah, I suspect that's the issue.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

So, do you get an UsageError after all now?

@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

Using ipdb:__main__.debugger_cls works for me. That seems to do what I was already doing with the changes that were introduced in 4.4.0.

That being said, if I wanted to expend the debugger class I cannot import one local to my project which is a new limitation. So I don't have the option of doing that anymore, as I was before the changes in 4.4.0

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

Yes, I see that it is a regression.. :)

I will fix it - after all it makes sense to not unnecessarily import it in the first place, i.e. make this more lazy.

@JBKahn

This comment has been minimized.

Copy link
Author

JBKahn commented Apr 3, 2019

Thanks, and thanks for the suggestion about using ipdb directly instead based on the new version. In this case it just simplified what I was already doing.

@blueyed

This comment has been minimized.

Copy link
Contributor

blueyed commented Apr 3, 2019

Yeah, I'm glad the new feature works for you - and somehow glad that it broke your current setup, since you might not have noticed otherwise.. :)
#5041 should fix it. I have some stashed change to make this more lazily even, but that is for later.

blueyed added a commit to blueyed/pytest that referenced this issue Apr 3, 2019

blueyed added a commit to blueyed/pytest that referenced this issue Apr 3, 2019

M157q added a commit to zdict/zdict that referenced this issue Apr 15, 2019

Update pytest to 4.4.1 (#337)
This PR updates [pytest](https://pypi.org/project/pytest) from **4.4.0** to **4.4.1**.



<details>
  <summary>Changelog</summary>
  
  
   ### 4.4.1
   ```
   =========================

Bug Fixes
---------

- `5031 &lt;https://github.com/pytest-dev/pytest/issues/5031&gt;`_: Environment variables are properly restored when using pytester&#39;s ``testdir`` fixture.


- `5039 &lt;https://github.com/pytest-dev/pytest/issues/5039&gt;`_: Fix regression with ``--pdbcls``, which stopped working with local modules in 4.0.0.


- `5092 &lt;https://github.com/pytest-dev/pytest/issues/5092&gt;`_: Produce a warning when unknown keywords are passed to ``pytest.param(...)``.


- `5098 &lt;https://github.com/pytest-dev/pytest/issues/5098&gt;`_: Invalidate import caches with ``monkeypatch.syspath_prepend``, which is required with namespace packages being used.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>

bors bot added a commit to rehandalal/therapist that referenced this issue Apr 17, 2019

Merge #67
67: Update pytest to 4.4.1 r=rehandalal a=pyup-bot


This PR updates [pytest](https://pypi.org/project/pytest) from **4.4.0** to **4.4.1**.



<details>
  <summary>Changelog</summary>
  
  
   ### 4.4.1
   ```
   =========================

Bug Fixes
---------

- `5031 &lt;https://github.com/pytest-dev/pytest/issues/5031&gt;`_: Environment variables are properly restored when using pytester&#39;s ``testdir`` fixture.


- `5039 &lt;https://github.com/pytest-dev/pytest/issues/5039&gt;`_: Fix regression with ``--pdbcls``, which stopped working with local modules in 4.0.0.


- `5092 &lt;https://github.com/pytest-dev/pytest/issues/5092&gt;`_: Produce a warning when unknown keywords are passed to ``pytest.param(...)``.


- `5098 &lt;https://github.com/pytest-dev/pytest/issues/5098&gt;`_: Invalidate import caches with ``monkeypatch.syspath_prepend``, which is required with namespace packages being used.
   ```
   
  
</details>


 

<details>
  <summary>Links</summary>
  
  - PyPI: https://pypi.org/project/pytest
  - Changelog: https://pyup.io/changelogs/pytest/
  - Homepage: https://docs.pytest.org/en/latest/
</details>



Co-authored-by: pyup-bot <github-bot@pyup.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.