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

Prevent pytest from printing ConftestImportFailure traceback #7257

Merged
merged 4 commits into from May 27, 2020

Conversation

DahlitzFlorian
Copy link
Member

Closes: #6956

@asottile I was not able to satisfy mypy so I added # type: ignore to the two lines. Let me know what you think :)

  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.
  • Create a new changelog file in the changelog folder, with a name like <ISSUE NUMBER>.<TYPE>.rst

src/_pytest/nodes.py Outdated Show resolved Hide resolved
@DahlitzFlorian
Copy link
Member Author

I moved the check to the correct position in the method and add ConftestImportFailure to the Union. However, I could not remove the second #type: ignore as ExceptionInfo does not accept a tuple of the form Tuple[Type[Exception], Exception, TracebackType], which excinfo.value.excinfo is.

Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @DahlitzFlorian.

I think the change make sense. Maybe there is a better place to handle this, but the way the code works now (conftests imported almost unintentionally in _gethookproxy?), it seems like the best place.

I left a few comments.

Also, _pytest/config/__init__.py already has some code to format ConftestImportFailure exceptions raised during initial conftest loading (added by @nicoddemus in #4124). Can some of the code be shared?

src/_pytest/nodes.py Outdated Show resolved Hide resolved
src/_pytest/nodes.py Outdated Show resolved Hide resolved
src/_pytest/nodes.py Outdated Show resolved Hide resolved
testing/test_reports.py Outdated Show resolved Hide resolved
@DahlitzFlorian
Copy link
Member Author

Thanks for the feedback @bluetech! I applied the suggested changes.

@bluetech
Copy link
Member

The code LGTM, just two things:

  • The tests fail on Python 3.5 -- seems like the exception type is different there.

  • According to the "patch" coverage report, the if isinstance(excinfo.value, ConftestImportFailure): branch isn't covered, which means the tests don't exercise it. Is it wrong or are the tests checking something else?

Also, did you see my comment about code sharing above? (It's OK if you don't want to dig into that)

@DahlitzFlorian
Copy link
Member Author

Thanks for the feedback!

  • I don't know why it's failing, but I saw a bunch of PRs failing on Python 3.5 but got merged.
  • The test covers exactly than bit of code, but I do not know why coverage flags it as not covered.
  • Yes, I had a look at it, but wasn't able to understand it in a way to be able to extend it and share the code (sorry for that)

@bluetech
Copy link
Member

I don't know why it's failing, but I saw a bunch of PRs failing on Python 3.5 but got merged.

The CI is gated on Python 3.5, i.e. the merge button is disabled if it is not passing.

Looking at the CI logs, the issue is that the test asserts for

E   ModuleNotFoundError: No module named 'unknown'

but on Python 3.5 it is

E   ImportError: No module named 'unknown'

so one way to take care of it is to assert just for

E   *Error: No module named 'unknown'

The test covers exactly than bit of code, but I do not know why coverage flags it as not covered.

Yes that's weird. I verified now that the if is indeed entered by the test.

@DahlitzFlorian
Copy link
Member Author

Fixed the py35 build.

@DahlitzFlorian
Copy link
Member Author

@asottile What do you think about the patch? Can it be merged?

Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

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

@asottile asottile added the needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch label May 27, 2020
@asottile asottile merged commit b3db440 into pytest-dev:master May 27, 2020
@asottile asottile added backported PR has been backported to the current bug-fix branch and removed needs backport applied to PRs, indicates that it should be ported to the current bug-fix branch labels May 27, 2020
asottile added a commit that referenced this pull request May 27, 2020
[5.4.x] Merge pull request #7257 from DahlitzFlorian/fix-issue-6956
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported PR has been backported to the current bug-fix branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConftestImportFailure: internal traceback when non-root conftest raises error
3 participants