GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||
GeezerVison is showing github.com — (fixtures): Replace fixture represenation with a class by Glyphack · Pull Request #12473 · pytest-dev/pytest Conversation
|
|
Hey @The-Compiler @RonnyPfannschmidt I rebased the PR could you please take a look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| src = inspect.getsource(deco_fixture) | ||
| # Since deco_fixture is now an instance of FixtureFunctionDef the getsource function will not work on it. | ||
| with pytest.raises(Exception): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could you assert against a more specific exception? As I understand, this is not testing that something went wrong but it's not clear what exactly. Also, it's usually a good idea to use the match= regex with this helper.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes will apply. This tries to document the behavior more than testing anything. Before introducing the FixtureFunctionDefinition it was possible to run inspect.getsource on fixtures but now it's not. This is just describing the behavior. I'm open to removing it as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I changed it to a more specific error. Do you think we can remove the test? This just tests that you cannot use inspect on fixture functions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove this test. I removed it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
f0324a5 to
9d2a916
Compare
|
Hey @Glyphack, could you resolve the merge conflicts / rebase this? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes will do today. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
641a3a1 to
bc0a0e5
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Iove where this is going
It opens up nice follow ups
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| """Get the real function object of the (possibly) wrapped object by | ||
| functools.wraps or functools.partial.""" | ||
| :func:`functools.wraps`, or :func:`functools.partial`, or :func:`pytest.fixture`.""" | ||
| from _pytest.fixtures import FixtureFunctionDefinition |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I believe we can drop fixture definition from that , we should pass the definitions attribute
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting to pass the FixtureFunctionDefinition object to this function? If I understand correctly this function is expected to take any object and return the real object according to this test testing the behavior:
https://github.com/Glyphack/pytest/blob/3d7416c2dd5dcf2d60a8b30636dcc90978c64215/testing/test_compat.py#L63
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As fixture definitions are no longer wrapping functions into other functions
The suggestion is to no longer consider them wrappers and passing the function directly
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@RonnyPfannschmidt Sorry I didn't fully understand your comment.
The current unwrapping behavior here is only for two cases:
The first case is handled by obj = obj._get_wrapped_function() line and second case is handled by obj = inspect.unwrap(obj, stop=lambda x: type(x) is FixtureFunctionDefinition).
If we drop any of them we cannot handle one of those two cases.
But I feel I am missing your point but unwrapping to me are these two lines.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Decorators cannot apply to a fixture definition
So that should trigger a error
It's wrong even now
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was wrong about that but the behavior is still needed. For example this test fails if we don't do unwrapping in this function:
https://github.com/Glyphack/pytest/blob/a6318c944f907bc350922c3961365e9ecd8d3e81/testing/python/integration.py#L11
The reason is that getfslineno is using this function to unwrap a decorator:
https://github.com/Glyphack/pytest/blob/a6318c944f907bc350922c3961365e9ecd8d3e81/src/_pytest/_code/code.py#L1341
I think the solution is to make a separate function for the cases when we want to perform the unwrapping? What is your suggestion?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What I meant is that we no longer ought to pass fixture definition to anything that unwrapped
Definition is no longer a function
Perhaps we should drop the call altogether
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks I realized the reason my code required this check to be here was that I was getting objects using the fixture name instead of their actual name and mistakenly I calling this on non fixture objects. After fixing that I could remove the get_real_method and simplify this function.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thank you both for the review. I left some TODO comments I will address them in a follow up PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Glyphack!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
* Carry around parameters and return value in `FixtureFunctionDefinition`. * Add `FixtureParams` to `FixtureDef`. Follow up to pytest-dev#12473.
* Carry around parameters and return value in `FixtureFunctionDefinition`. * Add `FixtureParams` to `FixtureDef`. Follow up to pytest-dev#12473.
|
FYI, this breaks pytest-factoryboy, but that's something I have to deal with. That being said, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
pytest-8.4.0 removed the __pytest_wrapped__ atribute on a fixture object, instead of unwrapping the object, it now keeps __wrapped__ that we can use instead. This commit makes sure we can work with both old and new pytest. See: pytest-dev/pytest#12473
pytest-8.4.0 removed the __pytest_wrapped__ atribute on a fixture object, instead of unwrapping the object, it now keeps __wrapped__ that we can use instead. This commit makes sure we can work with both old and new pytest. See: pytest-dev/pytest#12473
pytest-8.4.0 removed the __pytest_wrapped__ atribute on a fixture object, instead of unwrapping the object, it now keeps __wrapped__ that we can use instead. This commit makes sure we can work with both old and new pytest. See: pytest-dev/pytest#12473
Reference: pytest-dev/pytest#12473 Caused-by: smarie/python-pytest-cases#364
Reference: pytest-dev/pytest#12473 Caused-by: smarie/python-pytest-cases#364
pytest-dev/pytest#12473 removed `_pytestfixturefunction`. The `getfixturemarker` function is still private, but has existed across all pytest versions that we support. Fixes: bitprophet#33
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Show repr for callables used in an assert directly
There was an error while loading. Please reload this page.