Skip to content

Update pinned pytest version to 6.2.1 and fix error in test_exceptions.py::test_python_alreadyset_in_destructor - #2741

Merged
henryiii merged 5 commits into
pybind:masterfrom
YannickJadoul:pytest-6
Dec 24, 2020
Merged

Update pinned pytest version to 6.2.1 and fix error in test_exceptions.py::test_python_alreadyset_in_destructor#2741
henryiii merged 5 commits into
pybind:masterfrom
YannickJadoul:pytest-6

Conversation

@YannickJadoul

@YannickJadoulYannickJadoul commented Dec 23, 2020

Copy link
Copy Markdown
Collaborator

Description

As noted in #2573 (comment), pytest 6 seems to make one of our tests fail. Let's check this, and then figure out if/how to fix that.

Suggested changelog entry:

* Fix issue with a test failing on PyTest 6.2.

@YannickJadoul
YannickJadoul marked this pull request as draft December 23, 2020 23:10
@henryiii

Copy link
Copy Markdown
Collaborator

I think we just need to add a marker to turn this extra pytest feature off for this test. We do want this behavior.

I noticed the dropping of 3.5 in the changelog.

@YannickJadoul

YannickJadoul commented Dec 23, 2020

Copy link
Copy Markdown
CollaboratorAuthor

It would be nice if we could explicitly turn it off for just that test, though, and not for everything, with the blunt -p no:unraisableexception flags?

@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") ignores the warning, but still fails our test. Presumably because pytest holds sys.unraisablehook hostage, and doesn't propagate the behavior to the default implemenation, on which we depend in the test.

@bstaletic

Copy link
Copy Markdown
Collaborator

Can we use the monkeypatch fixture to force our hook and then restore pytest's hook?

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Got something. The original built-in sys.unraisablehook is kept as sys.__unraisablehook__, so we can just use that?

@YannickJadoulYannickJadoul changed the title Test (and hopefully soon fix) test failure with pytest 6Update pinned pytest version to 6 and fix error in test_exceptions.py::test_python_alreadyset_in_destructorDec 23, 2020
@YannickJadoul
YannickJadoul marked this pull request as ready for review December 23, 2020 23:49
@YannickJadoulYannickJadoul changed the title Update pinned pytest version to 6 and fix error in test_exceptions.py::test_python_alreadyset_in_destructorUpdate pinned pytest version to 6.2.1 and fix error in test_exceptions.py::test_python_alreadyset_in_destructorDec 23, 2020
@henryiii

henryiii commented Dec 23, 2020

Copy link
Copy Markdown
Collaborator

Why make it a string but still error out if unfound, PyTest... needs an if to see if that exception exists.

Comment threadtests/test_exceptions.py Outdated
"ignore::pytest.PytestUnraisableExceptionWarning"
)
else:
ignore_pytest_unraisable_warning = lambda f: f # NOQA: E731

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yes, I could not put a lambda, and put 2 lines def ignore_pytest_unraisable_warning(f): and return f, but then black suddenly adds an empty line after else:, so that's just as ugly.

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Why make it a string but still error out if unfound, PyTest... needs an if to see if that exception exists.

Yeah, indeed ... :-/ Guess they're just following the warnings module?

Comment threadtests/test_exceptions.py Outdated
assert d["good"] is True


if hasattr(pytest, "PytestUnraisableExceptionWarning"): # Python >= 3.8 and pytest >= 6

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Alternatively, we move this into the function, and directly use the warnings module. But I'm not sure whether such a filter would get reset after the test or not, this way.

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Green! :-) Ready to be reviewed.

@bstaleticbstaletic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Like I said "a decorator factory" could be a fancy way of avoiding code in global scope, but not a blocker.

Comment threadtests/test_exceptions.py Outdated
hooked = True
default_hook = sys.unraisablehook
# Don't take `sys.unraisablehook`, as that's overwritten by pytest
default_hook = sys.__unraisablehook__

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I take it we're happy with this?

If some case where this would be overwritten (by something else than pytest), we're ignoring it as well, ofc, but ... myeah, best I could immediately think of.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, it seems fine to me. We don't want pytest's version here, and it's a test, so nothing else should be fiddling with it.

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Does this need to be marked 2.6.2, still? I guess it's kind of independent from the releases, but ...

Guess it's mostly #2573 that needs to make sure it also installs tests/requirements.txt, as I noted there.

@henryiiihenryiii added this to the v2.6.2 milestone Dec 24, 2020
@henryiii
henryiii merged commit 830f8ed into pybind:masterDec 24, 2020
@github-actionsgithub-actionsBot added the needs changelog Possibly needs a changelog entry label Dec 24, 2020
@henryiii

Copy link
Copy Markdown
Collaborator

Great! We don't really control the PyTest version if someone wants to run our tests (a requirements.txt is an internal pinning, not an external one), and a few of our tests use system PyTests, but it's good not to be (too) version specific, tests failing due to PyTest is not ideal.

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Do you want a changelog for this, @henryiii?

@henryiii

Copy link
Copy Markdown
Collaborator

Yes, I added it to the description.

Here it is in setuptools changelog, for example: https://setuptools.readthedocs.io/en/latest/history.html#misc

@YannickJadoul

Copy link
Copy Markdown
CollaboratorAuthor

Yes, I added it to the description.

Great! Hadn't spotted that; thanks! :-)

@henryiiihenryiii removed the needs changelog Possibly needs a changelog entry label Dec 29, 2020
@rwgkrwgk mentioned this pull request Feb 10, 2023
Sign up for freeto 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

@YannickJadoul@henryiii@bstaletic