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

Actually deprecate long standing features #3978

Conversation

nicoddemus
Copy link
Member

This issues proper warnings for:

  • Compatible properties
  • cached_setup
  • Using special named objects to customize node objects during class creation.

This fixes #3616. It also supports a new type of changelog entry, "deprecations", so we can show Deprecations separated from Removals.

@RonnyPfannschmidt are other features you remember of that we should issue deprecation warnings? Would love to add to them as well.

Also it follows that we should not merge #3898, as now we have a proper way to turn the warnings into errors in pytest-4.0, to effectively remove them in 4.1. 👍

# "usage of {owner!r}.{name} is deprecated, please use pytest.{name} instead".format(
# name=self.name, owner=type(owner).__name__),
# PendingDeprecationWarning, stacklevel=2)
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had massive issue about one part of those warnings being triggered from pytest internals by accident which is why i deffered it on the old warnings system

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch_warnings to the rescue. 😁

It won't show the warnings for this specific access, but I guess that's OK because the whole class will be kicked out anyway. 👍

@@ -800,7 +800,7 @@ def collect(self):
"%r generated tests with non-unique name %r" % (self, name)
)
seen[name] = True
values.append(self.Function(name, self, args=args, callobj=call))
values.append(Function(name, self, args=args, callobj=call))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a breaking change, not doing it is why i had massive trouble with the warnings

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move the actual warning texts/instances to the deprecation modules

also we should take a look at creating a minimal tool for creating warnings that will be formatted at display time

@nicoddemus
Copy link
Member Author

please move the actual warning texts/instances to the deprecation modules

Argh I missed that point. Definitely, will do.

also we should take a look at creating a minimal tool for creating warnings that will be formatted at display time

Can you please clarify what you mean here?

@coveralls
Copy link

coveralls commented Sep 13, 2018

Coverage Status

Coverage increased (+0.03%) to 93.913% when pulling ae8f369 on nicoddemus:warn-yield-and-compat-properties into 53c9124 on pytest-dev:features.

@RonnyPfannschmidt
Copy link
Member

we do have more and more warnings where we format in code - its not nice to use them in code as one has to import the message and still pick the correct category

instead of warn(SomeWarningType(CONSTANT.format(foo))) i want to write warn(CONSTANT.format(foo))

@nicoddemus
Copy link
Member Author

nicoddemus commented Sep 13, 2018

we do have more and more warnings where we format in code - its not nice to use them in code as one has to import the message and still pick the correct category

I suppose we can have format method in our warnings that returns a new instance of that warning, but applying the formatting.

Could be simply:

class PytestWarning:
    def format(self, *args, **kwargs):
        return type(self)(self.args[0].format(*args, **kwargs))

FUNCARG_PREFIX = RemovedInPytest4Warning(
    '{name}: declaring fixtures using "pytest_funcarg__" prefix is deprecated')

Usage:

warn(FUNCARG_PREFIX.format(name=f.name))

@RonnyPfannschmidt
Copy link
Member

RonnyPfannschmidt commented Sep 14, 2018

instead i would like to see a

@attr.s
class UnformattedWarning(object):
    category = attr.ib()
    template = attr.ib()

    def format(self, **kw):
        return self.category(self.template.format(**kw))

FUNCARG_PREFIX = UnformattedWarning(
   RemovedInPytest4Warning,
   '{name}: declaring fixtures using "pytest_funcarg__" prefix is deprecated',
)

that way we have a much better indicator of missuse

@nicoddemus
Copy link
Member Author

Oh great idea. I will implement it then. 👍

@nicoddemus
Copy link
Member Author

Implemented @RonnyPfannschmidt! The result is much better, thanks for the suggestion.

I also found one warning which was using the wrong category, I fixed and noted in the CHANGELOG. 👍

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fabulous work, thanks

@RonnyPfannschmidt RonnyPfannschmidt merged commit bceaede into pytest-dev:features Sep 15, 2018
@nicoddemus nicoddemus deleted the warn-yield-and-compat-properties branch September 15, 2018 15:07
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

Successfully merging this pull request may close these issues.

3 participants