-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Override marks on items? #3501
Comments
your usage adds markdecorators into places where marks are, add_marker correctly appends a actual mark object insertion a point zero is technically always wrong the marker object is available as mark property on the markdecorator |
now however you exposed that get_closest_marker is not entirely correct, it should get the last marker first so your added one should be closer than the original one |
since we didn't introduce get_closest_marker as experiment we also cant fix it without doing an api breaking change ^^ aint this a nice bill |
@nicoddemus i just noted i wasnt clear enough - you can add the mark object via |
Hmm I see, thanks! Worth noting that this is an API breakage, because |
@nicoddemus yes, i#ll take a look in the afternoon |
Hmm wait, I mis-remembered this issue: Weird, I was trying the example again and it was not generating an error. Then I realized I was in Python 3. Switching to Python 2 then I get the error. To recapitulate: import pytest
@pytest.mark.timeout(1)
def test_replace_mark(request):
m = request.node.get_closest_marker('timeout')
value = m.args[0]
request.node.own_markers.insert(0, pytest.mark.timeout(value * 3))
assert request.node.get_marker('timeout').args[0] == 3 Python 2
Python 3
|
@nicoddemus the error doesnt happen on python3 due to disappearance of bound methods - if marks get required to be marks for markinfo, it will fail earlier |
@nicoddemus i got a fix - preparing a pr |
closed by #3576 |
We have a lot of C++ code which runs with our Python tests. Running tests in debug mode is significantly slower than running in release, so we have a
pytest_collection_modifyitems
hook that goes over all items and increases their timeout (we usepytest-timeout
) if in debug mode.The hook basically gets the current timeout marker (if any), multiplies its timeout value by 3 if in debug mode, and sets a new marker in the node with the new timeout value.
Here's a test which in essence does same as the hook:
This fails because
args[0] == 1
, which is the value of the@pytest.mark.timeout(1)
applied directly to the test. I supposeget_closest_marker
looks at the first marker on theown_markers
list, which makes sense.If I explicitly insert the marker to the front of
own_markers
then the test works:But we need to realize that
pytest-timeout
still uses the oldNode.get_marker
API. So if we change the assert to:This fails with:
I can fix that by inserting a
Mark
object explicitly:That fixes the test, but requires to import
_pytest.mark.structures.Mark
.All in all this exposes how tricky the old implementation/API were, but I'm bringing this up for discussion because it is not very clear how overwrite or add a new marker with precedence over the others.
The text was updated successfully, but these errors were encountered: