Skip to content

Add alias clarification to deprecation warning - #7829

Merged
nicoddemus merged 3 commits into
pytest-dev:masterfrom
mmarinez:misleading-warning
Oct 6, 2020
Merged

nicoddemus merged 3 commits into
pytest-dev:masterfrom
mmarinez:misleading-warning

Conversation

@mmarinez

@mmarinez mmarinez commented Oct 2, 2020 •

Copy link
Copy Markdown
Contributor

@Zac-HD Yes, this is related to the issue #7815. I could come up with a better format for the warning if it is needed.

@nicoddemus

Copy link
Copy Markdown
Member

Hi @mmarinez,

Can you clarify why the clarification is needed?

@The-Compiler

Copy link
Copy Markdown
Member

Can you elaborate on why this is needed? I don't see how it'd be relevant for users how the private implementation of the underlying function is called. Also FWIW the tests are failing, but I don't see why this would be needed at all.

@Zac-HD

Zac-HD commented Oct 2, 2020

Copy link
Copy Markdown
Member

Related to #7815?

@The-Compiler

Copy link
Copy Markdown
Member

@mmarinez Thanks for the clarification! In the future, please clarify the context of a PR as part of the PR message when you open it - you can even use something like "Closes #7815" so that the issue is closed automatically when the PR is merged. This makes it easier for people to keep track of things, as there are a lot of stuff going on in parallel in a project like this.

@The-Compiler The-Compiler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't really understand #7815 (though I only took a quick look), so I'll let someone else take a closer look at this. However, note that test_fillfuncargs_is_deprecated in testing/deprecated_test.py will need adjustments to fix the tests.

@mmarinez

mmarinez commented Oct 2, 2020

Copy link
Copy Markdown
Contributor Author

I don't really understand #7815 (though I only took a quick look), so I'll let someone else take a closer look at this. However, note that test_fillfuncargs_is_deprecated in testing/deprecated_test.py will need adjustments to fix the tests.

Got it, thanks for letting me know, I'll be checking that out.

@bluetech

bluetech commented Oct 3, 2020

Copy link
Copy Markdown
Member

LGTM once CI passes, thanks @mmarinez.

@bluetech bluetech added the needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch label Oct 3, 2020
@mmarinez
mmarinez force-pushed the misleading-warning branch from 0a00349 to 7955b6f Compare October 3, 2020 14:34
@mmarinez
mmarinez force-pushed the misleading-warning branch from 7955b6f to 5381e1c Compare October 3, 2020 14:52
@nicoddemus

Copy link
Copy Markdown
Member

Hi @mmarinez,

Thanks for working on this. I took the liberty of updating the PR a bit:

  • Instead of an alias, I created an actual _pytest.fixtures._fillfuncargs() function which issues the warning.
  • _pytest.fixtures.fillfixtures() no longer issues a warning, it is already an internal function.
  • Because of the above, the message now points users to use _pytest.fixtures.fillfixtures() instead, which is just internal API and just passive of changing in the future as function._request._fillfixtures(), but is a bit nicer.

With this change:

import pytest

def test1():
    pytest._fillfuncargs(mock.Mock())

Produces this warning:

test_foo.py::test1
  d:\projects\pytest\.tmp\test_foo.py:7: PytestDeprecationWarning: pytest._fillfuncargs() is deprecated, use _pytest.fixtures.fillfixtures() instead if you cannot avoid reaching into internals.
    pytest._fillfuncargs(mock.Mock())

Which I think is better. 👍

@bluetech can you please take another look?

@mmarinez for the record, the test was failling previously because match= expects a regular expression, and your message contained () so it needed to be escaped with re.escape.

@bluetech

bluetech commented Oct 4, 2020

Copy link
Copy Markdown
Member

@nicoddemus The idea is to eventually remove the _pytest.fixtures.fillfixtures function entirely as well, not just the public alias. And the issue was triggered by a plugin which actually uses the internal name. Long story short, I'd like _pytest.fixtures.fillfixtures to continue to issue a deprecation warning.

@nicoddemus

Copy link
Copy Markdown
Member

@nicoddemus The idea is to eventually remove the _pytest.fixtures.fillfixtures function entirely as well, not just the public alias. And the issue was triggered by a plugin which actually uses the internal name. Long story short, I'd like _pytest.fixtures.fillfixtures to continue to issue a deprecation warning.

I understand, but let me make a few points why I think the current PR is better, but if you still prefer to keep _pytest.fixtures.fillfixtures() deprecated I will change it back:

  • _pytest.fixtures.fillfixtures() is already private.
  • We don't have a good (public) alternative to point users to to show in the deprecation message.
  • function._request._fillfixtures() is even easier to break by accident.

If we had a better alternative to point to (specially a new, public usage), I would agree 100% with you, but pointing to function._request._fillfixtures() vs _pytest.fixtures.fillfixtures() are both "private and use at your own risk", with the former being slightly better.

WDYT?

@mmarinez

mmarinez commented Oct 5, 2020

Copy link
Copy Markdown
Contributor Author

Hi @mmarinez,

Thanks for working on this. I took the liberty of updating the PR a bit:

* Instead of an alias, I created an actual `_pytest.fixtures._fillfuncargs()` function which issues the warning.

* `_pytest.fixtures.fillfixtures()` no longer issues a warning, it is already an internal function.

* Because of the above, the message now points users to use `_pytest.fixtures.fillfixtures()` instead, which is just internal API and just passive of changing in the future as `function._request._fillfixtures()`, but is a bit nicer.

With this change:

import pytest

def test1():
    pytest._fillfuncargs(mock.Mock())

Produces this warning:

test_foo.py::test1
  d:\projects\pytest\.tmp\test_foo.py:7: PytestDeprecationWarning: pytest._fillfuncargs() is deprecated, use _pytest.fixtures.fillfixtures() instead if you cannot avoid reaching into internals.
    pytest._fillfuncargs(mock.Mock())

Which I think is better. 👍

@bluetech can you please take another look?

@mmarinez for the record, the test was failling previously because match= expects a regular expression, and your message contained () so it needed to be escaped with re.escape.

Hey, it's ok thank. I was actually struggling a bit trying to run the tests locally and not push every change trying to figure why were the tests failing

@bluetech

bluetech commented Oct 5, 2020

Copy link
Copy Markdown
Member

@nicoddemus

_pytest.fixtures.fillfixtures() is already private.

Right, although there are plugins which use it.

We don't have a good (public) alternative to point users to to show in the deprecation message.

Right.

function._request._fillfixtures() is even easier to break by accident.

But that's fine? I mean this is clearly entirely private, so if someone is using that they can't expect it to be stable.

A better alternative is to use request.fixturenames, function.fixturenames, request.getfixturevalue() directly (basically what function._request._fillfixtures() does internally), these are at least more public/stable, but it's not a direct replacement.

If we had a better alternative to point to (specially a new, public usage), I would agree 100% with you, but pointing to function._request._fillfixtures() vs _pytest.fixtures.fillfixtures() are both "private and use at your own risk", with the former being slightly better.

I agree function._request._fillfixtures() is slightly better (because I want to remove _pytest.fixtures.fillfixtures() eventually, and it's more obviously private), that's why I prefer to keep pointing to it (and just remove mentioning it) and keep _pytest.fixtures.fillfixtures() deprecated.

@nicoddemus

Copy link
Copy Markdown
Member

I agree function._request._fillfixtures() is slightly bette

Hehehe I meant the latter.

No worries, I will re-add the deprecation warning and improve the message. 👍

@nicoddemus

Copy link
Copy Markdown
Member

Done! 👍

@bluetech bluetech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nicoddemus
nicoddemus merged commit 13ddec9 into pytest-dev:master Oct 6, 2020
nicoddemus added a commit to nicoddemus/pytest that referenced this pull request Oct 6, 2020
@nicoddemus

Copy link
Copy Markdown
Member

Backport: #7867

@nicoddemus nicoddemus added backported and removed needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch labels Oct 6, 2020
@mmarinez
mmarinez deleted the misleading-warning branch October 6, 2020 16: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.

misleading warning about _fillfuncargs when calling fillfixtures

5 participants