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

Deprecation warnings when using Pytest #571

Open
ZatkovaV opened this issue Oct 12, 2018 · 6 comments
Open

Deprecation warnings when using Pytest #571

ZatkovaV opened this issue Oct 12, 2018 · 6 comments

Comments

@ZatkovaV
Copy link

ZatkovaV commented Oct 12, 2018

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!

@rmmcnulty9
Copy link

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

@rmmcnulty9
Copy link

Looks like this might be fixed with #576

@jesuslosada
Copy link
Contributor

jesuslosada commented Nov 14, 2018

@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

@ryanhiebert
Copy link

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.

@joaodlf
Copy link

joaodlf commented Jan 24, 2019

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

@fx-kirin
Copy link

fx-kirin commented Feb 19, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@ryanhiebert @rmmcnulty9 @fx-kirin @joaodlf @jesuslosada @ZatkovaV and others