Skip to content

TypeError: warn() takes at most 3 arguments (4 given), with pytest 3.9.2 #4243

@andy-maier

Description

@andy-maier

Since pytest 3.9.2, the following TypeError is raised from within pytest.warns():

/Users/maiera/virtualenvs/pywbem27/lib/python2.7/site-packages/_pytest/recwarn.py:172: TypeError
___________________________________ TestCreateConnection.test_namespace_slashes_set ____________________________________

self = <test_cim_operations.TestCreateConnection object at 0x11649ecd0>

    def test_namespace_slashes_set(self):  # pylint: disable=no-self-use
        """Test stripping of leading and trailing slashes in default namespace
        of wbem connection when setting the attribute"""
        conn = WBEMConnection('http://localhost', None,
                              default_namespace=None)
        with pytest.warns(DeprecationWarning):
>           conn.default_namespace = '//root/blah//'

testsuite/test_cim_operations.py:130: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pywbem/cim_operations.py:740: in default_namespace
    "deprecated", DeprecationWarning, 2)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = ('Setting the WBEMConnection.default_namespace property is deprecated', <type 'exceptions.DeprecationWarning'>, 2)
kwargs = {'stacklevel': 2}
f_globals = {'AUTO_GENERATE_SFCB_UEP_HEADER': True, 'CIMClass': <class 'pywbem.cim_obj.CIMClass'>, 'CIMClassName': <class 'pywbem.cim_obj.CIMClassName'>, 'CIMDateTime': <class 'pywbem.cim_types.CIMDateTime'>, ...}

    def warn(*args, **kwargs):
        kwargs.setdefault("stacklevel", 1)
        kwargs["stacklevel"] += 1
    
        # emulate resetting the warn registry
        f_globals = sys._getframe(kwargs["stacklevel"] - 1).f_globals
        if "__warningregistry__" in f_globals:
            orig = f_globals["__warningregistry__"]
            f_globals["__warningregistry__"] = None
            try:
                return self._saved_warn(*args, **kwargs)
            finally:
                f_globals["__warningregistry__"] = orig
        else:
>           return self._saved_warn(*args, **kwargs)
E           TypeError: warn() takes at most 3 arguments (4 given)

/Users/maiera/virtualenvs/pywbem27/lib/python2.7/site-packages/_pytest/recwarn.py:172: TypeError

This is with all dependent Python packages being on the latest available package level, as of today.

When I reinstall pytest==3.9.1, the TypeError is not raised and the tests succeed as before.

We'll exclude pytest!=3.9.2 for the time being

  • Include a detailed description of the bug or suggestion
    see above
  • pip list of the virtual environment you are using
Package                            Version       Location
---------------------------------- ------------- --------------------------------
alabaster                          0.7.12
astroid                            1.6.5
atomicwrites                       1.2.1
attrs                              18.2.0
Babel                              2.6.0
backports-abc                      0.5
backports.functools-lru-cache      1.5
backports.shutil-get-terminal-size 1.0.0
bleach                             3.0.2
certifi                            2018.10.15
chardet                            3.0.4
configparser                       3.5.0
coverage                           4.0.3
decorator                          4.3.0
defusedxml                         0.5.0
distro                             1.3.0
docutils                           0.14
entrypoints                        0.2.3
enum34                             1.1.6
flake8                             3.6.0
funcsigs                           1.0.2
functools32                        3.2.3.post2
future                             0.17.0
futures                            3.2.0
gitdb2                             2.0.5
GitPython                          2.1.11
httpretty                          0.9.5
idna                               2.7
imagesize                          1.1.0
ipaddress                          1.0.22
ipykernel                          4.10.0
ipython                            5.8.0
ipython-genutils                   0.2.0
ipywidgets                         7.4.2
isort                              4.3.4
Jinja2                             2.10
jsonschema                         2.6.0
jupyter                            1.0.0
jupyter-client                     5.2.3
jupyter-console                    5.2.0
jupyter-core                       4.4.0
lazy-object-proxy                  1.3.1
linecache2                         1.0.0
lxml                               4.2.5
M2Crypto                           0.30.1
MarkupSafe                         1.0
mccabe                             0.6.1
mistune                            0.8.4
mock                               2.0.0
more-itertools                     4.3.0
nbconvert                          5.4.0
nbformat                           4.4.0
nose                               1.3.7
notebook                           5.7.0
numpy                              1.13.3
packaging                          18.0
pandocfilters                      1.4.2
pathlib2                           2.3.2
pbr                                5.1.0
pexpect                            4.6.0
pickleshare                        0.7.5
pip                                18.1
pkginfo                            1.4.2
pluggy                             0.8.0
ply                                3.11
prometheus-client                  0.4.2
prompt-toolkit                     1.0.15
ptyprocess                         0.6.0
py                                 1.5.2
pycodestyle                        2.4.0
pyflakes                           2.0.0
Pygments                           2.2.0
pylint                             1.9.3
pyparsing                          2.2.2
pytest                             3.9.2
pytest-cov                         2.5.1
python-coveralls                   2.9.1
python-dateutil                    2.7.4
pytz                               2018.6
pywbem                             0.12.1.dev133 /home/travis/build/pywbem/pywbem
PyYAML                             3.13
pyzmq                              17.1.2
qtconsole                          4.4.2
readme-renderer                    23.0
requests                           2.20.0
requests-toolbelt                  0.8.0
scandir                            1.9.0
Send2Trash                         1.5.0
setuptools                         40.4.3
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
six                                1.11.0
smmap2                             2.0.5
snowballstemmer                    1.2.1
Sphinx                             1.8.1
sphinx-git                         10.1.1
sphinxcontrib-websupport           1.1.0
terminado                          0.8.1
testfixtures                       5.4.0
testpath                           0.4.2
tornado                            4.5.3
tqdm                               4.28.1
traceback2                         1.4.0
traitlets                          4.3.2
twine                              1.12.1
typing                             3.6.6
unittest2                          1.1.0
urllib3                            1.24
wcwidth                            0.1.7
webencodings                       0.5.1
wheel                              0.32.2
widgetsnbextension                 3.4.2
wrapt                              1.10.11
yamlordereddictloader              0.4.0         
  • pytest and operating system versions
    • MacOS High Sierra, but happens also on Ubuntu 16.04 (Travis) and Windows (Appveyor)
    • Python 2.7.15 (on mac), Python 3.4 (on Travis)
  • Minimal example if possible
    The following is a simple version of the code that caused the TypeError to be raised, and I verified that it reproduces the issue with pytest==3.9.2 (and that it succeeds with pytest==3.9.1):
#!/usr/bin/env python

import pytest
import warnings

def issue_warning():
   warnings.warn(
        "Setting the xyz property is deprecated",
        DeprecationWarning, 2)

def test_warn():
    with pytest.warns(DeprecationWarning):
        issue_warning()

Metadata

Metadata

Labels

plugin: warningsrelated to the warnings builtin plugintype: bugproblem that needs to be addressedtype: regressionindicates a problem that was introduced in a release which was working previously

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions