schematics/schematics

Deprecation warnings when using Pytest

ZatkovaV opened this issue ยท 6 comments

I use schematics to define models for requests and responses in simple Flask API.
However, when running tests with Pytest, I encounter many SchematicsDeprecationWarning warnings.

The warnings are as following:

...lib/python3.7/site-packages/schematics/transforms.py:103: SchematicsDeprecationWarning: Call to deprecated function _valid_input_keys.
  all_fields = schema._valid_input_keys
...lib/python3.7/site-packages/schematics/validate.py:91: SchematicsDeprecationWarning: Call to deprecated function _validator_functions.
  atom.name in schema._validator_functions
...lib/python3.7/site-packages/schematics/transforms.py:103: SchematicsDeprecationWarning: Call to deprecated function _valid_input_keys.
  all_fields = schema._valid_input_keys
...lib/python3.7/site-packages/schematics/transforms.py:249: SchematicsDeprecationWarning: Call to deprecated function _options.
  if schema._options.export_order:
...lib/python3.7/site-packages/schematics/transforms.py:255: SchematicsDeprecationWarning: Call to deprecated function _options.
  schema._options.roles.get(context.role))
...lib/python3.7/site-packages/schematics/transforms.py:261: SchematicsDeprecationWarning: Call to deprecated function _options.
  filter_func = schema._options.roles.get("default")
...lib/python3.7/site-packages/schematics/deprecated.py:65: SchematicsDeprecationWarning: Call to deprecated function _options.
  return super(class_property, self).__get__(type, type)
...lib/python3.7/site-packages/schematics/deprecated.py:65: SchematicsDeprecationWarning: Call to deprecated function _options.
  return super(class_property, self).__get__(type, type)
...lib/python3.7/site-packages/schematics/deprecated.py:65: SchematicsDeprecationWarning: Call to deprecated function _options.
  return super(class_property, self).__get__(type, type)

Is there something I can do in order to solve this issue? My schematics version is 2.1.0 and the issue happens with using Python 3.7.0 as well as Python 3.5.2. Thanks!

I needed to set this env var to get around this. But this seems like a bad solution: PYTHONWARNINGS=0

Looks like this might be fixed with #576

@rmmcnulty9 @tomasbedrich Note that #576 only fixes the deprecation warnings related to the standard library. There are additional warnings generated by Schematics because some features are deprecated but are still being used (?). You can at least ignore those warnings passing this parameter to pytest:
-W ignore::schematics.deprecated.SchematicsDeprecationWarning

I'm personally getting a flood of warnings from schematics like this:

  /home/ryan/.local/share/virtualenvs/aspiredu-sa7rbeeh/lib/python3.6/site-packages/schematics/transforms.py:103: SchematicsDeprecationWarning: Call to deprecated function_valid_input_keys.
    all_fields = schema._valid_input_keys
  /home/ryan/.local/share/virtualenvs/aspiredu-sa7rbeeh/lib/python3.6/site-packages/schematics/validate.py:91: SchematicsDeprecationWarning: Call to deprecated function _validator_functions.
    atom.name in schema._validator_functions

The only thing interesting that I think I'm doing is that I make sure that my models are automatically validated on instantiation like this:

class SchoologyObject(Model):
    """A base class for objects returned by the schoology API."""

    def __init__(self, *args, **kwargs):
        kwargs.setdefault('strict', False)
        kwargs.setdefault('validate', True)
        super().__init__(*args, **kwargs)

@jesuslosada's workaround to ignore those warnings works for me, but of course I'd rather be able to have my code written so that it doesn't raise the warnings, rather than having to silence them.

I'm also getting quite a few warnings from pytest:

/env/lib/python3.6/site-packages/schematics/validate.py:123: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
    if len(inspect.getargspec(func).args) < argcount:

/env/lib/python3.6/site-packages/schematics/validate.py:123: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
    if len(inspect.getargspec(func).args) < argcount:

/env/lib/python3.6/site-packages/schematics/deprecated.py:66: SchematicsDeprecationWarning: Call to deprecated function _fields.
    return super(class_property, self).__get__(instance, type)

/env/lib/python3.6/site-packages/schematics/transforms.py:103: SchematicsDeprecationWarning: Call to deprecated function _valid_input_keys.
    all_fields = schema._valid_input_keys

According to this stackoverflow answer, you can also fix it to add warnings.filterwarnings("ignore", category=schematics.deprecated.SchematicsDeprecationWarning) in setup_module function of pytest. it's annoying anyway.

def setup_module(module):
    warnings.filterwarnings("ignore", category=schematics.deprecated.SchematicsDeprecationWarning)