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

Using removed pytest warning function for error reporting #394

Closed
loksonarius opened this issue Jan 18, 2019 · 2 comments
Closed

Using removed pytest warning function for error reporting #394

loksonarius opened this issue Jan 18, 2019 · 2 comments
Assignees
Labels
bug This issue/PR relates to a bug.

Comments

@loksonarius
Copy link

So while playing around with molecule, I tried running my first Testinfra specs. All good, but things would fail before even running my test. Sample output:

    ============================= test session starts ==============================
    platform darwin -- Python 3.6.5, pytest-4.1.1, py-1.7.0, pluggy-0.8.1
    rootdir: /Users/myusernamehere/Projects/personal/consul-appliance/molecule/default, inifile:
    plugins: testinfra-1.16.0
collected 2 items
    INTERNALERROR> Traceback (most recent call last):
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/_pytest/main.py", line 203, in wrap_session
    INTERNALERROR>     session.exitstatus = doit(config, session) or 0
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/_pytest/main.py", line 242, in _main
    INTERNALERROR>     config.hook.pytest_collection(session=session)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
    INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/manager.py", line 68, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/manager.py", line 62, in <lambda>
    INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    INTERNALERROR>     raise ex[1].with_traceback(ex[2])
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/_pytest/main.py", line 252, in pytest_collection
    INTERNALERROR>     return session.perform_collect()
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/_pytest/main.py", line 471, in perform_collect
    INTERNALERROR>     hook.pytest_collection_finish(session=self)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/hooks.py", line 284, in __call__
    INTERNALERROR>     return self._hookexec(self, self.get_hookimpls(), kwargs)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/manager.py", line 68, in _hookexec
    INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/manager.py", line 62, in <lambda>
    INTERNALERROR>     firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 208, in _multicall
    INTERNALERROR>     return outcome.get_result()
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 80, in get_result
    INTERNALERROR>     raise ex[1].with_traceback(ex[2])
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/pluggy/callers.py", line 187, in _multicall
    INTERNALERROR>     res = hook_impl.function(*args)
    INTERNALERROR>   File "/Users/myusernamehere/Projects/personal/consul-appliance/venv/lib/python3.6/site-packages/testinfra/plugin.py", line 183, in pytest_collection_finish
    INTERNALERROR>     session.config.warn('C1', msg)
    INTERNALERROR> AttributeError: 'Config' object has no attribute 'warn'

    ========================= no tests ran in 0.66 seconds =========================

I dug into the source code and found that the pytest hook function pytest_collection_finish (line 160 of plugin.py in the version of Testinfra I'm using), was failing to call session.config.warn.

From this point, I've come to realize I can avoid this call entirely by using the non-deprecated syntax of host.XXX instead of passing XXX as a parameter (in my case, XXX was the User module). This means my tests are now able to run cause I avoid that conditional branch of the if tree entirely.

From my digging before realizing this problem, I started looking through the pytest_hookspec, which lead me to this section of the pytest source code, where I noticed an oddly relevant commit message that was linked to this relevant discussion. Based off that discussion, it seems like there was a plan to deprecate and fully remove the .warn function from the Config object. I couldn't understand what changes consumers needed to make as I'm a bit of a scrub when it comes to Python 😄 , but it looks like version 4.0.X of pytest will require calls to the .warn function to be replaced with some new usage of a warning system. I'd offer a code change, but I honestly am very new to Python, let alone what looks to be advanced Python programing.

I don't have any pressing need for a fix on this, but wanted to open this issue in case a hard reason for adding pytest 4.0 support was needed.

@philpep philpep self-assigned this Jan 19, 2019
@philpep philpep added the bug This issue/PR relates to a bug. label Jan 19, 2019
philpep added a commit that referenced this issue Jan 19, 2019
Use warnings from python instead.

Closes #394
@philpep
Copy link
Contributor

philpep commented Jan 19, 2019

Hi, thanks for reporting and digging into this issue. A fix is coming and will be released asap !

philpep added a commit that referenced this issue Jan 19, 2019
Use warnings from python instead.

Closes #394
@philpep
Copy link
Contributor

philpep commented Jan 19, 2019

Fixed in 1.19.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants