GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix: pytest >=8.1.0 displays no diff for AssertionError with `--impor… by dongfangtianyu · Pull Request #12716 · pytest-dev/pytest

Conversation

@dongfangtianyu

@dongfangtianyu dongfangtianyu commented Aug 15, 2024

Copy link
Copy Markdown
Contributor

closes #12659

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 15, 2024
@dongfangtianyu
dongfangtianyu force-pushed the bugfix-12659 branch from 7a195c1 to a8250cb Compare August 15, 2024 10:18
nicoddemus
nicoddemus requested changes Aug 16, 2024
View reviewed changes

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks a lot @dongfangtianyu!

Please take a look at the comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/_pytest/assertion/rewrite.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread testing/test_pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread testing/test_pathlib.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread changelog/12659.bugfix.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@nicoddemus nicoddemus added the backport 8.3.x label Aug 16, 2024
@dongfangtianyu
Fix: pytest >=8.1.0 displays no diff for AssertionError with `--impor…
9122f6e
…t-mode=importlib` (pytest-dev#12659)
@dongfangtianyu
dongfangtianyu force-pushed the bugfix-12659 branch from a8250cb to 9122f6e Compare August 16, 2024 11:17
@dongfangtianyu

dongfangtianyu commented Aug 16, 2024

Copy link
Copy Markdown
Contributor Author

Thanks @nicoddemus ,resubmitted according to the comments

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nicoddemus
nicoddemus approved these changes Aug 16, 2024
View reviewed changes

@nicoddemus nicoddemus left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks @dongfangtianyu!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nicoddemus
nicoddemus merged commit 9a444d1 into pytest-dev:main Aug 30, 2024
@patchback

patchback Bot commented Aug 30, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Backport to 8.3.x: 💚 backport PR created

✅ Backport PR branch: patchback/backports/8.3.x/9a444d113658be6ccb8dc9f57ed118a1ef17c94c/pr-12716

Backported as #12755

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

patchback Bot pushed a commit that referenced this pull request Aug 30, 2024
@dongfangtianyu @patchback
Fix assertion rewriting with importlib mode (#12716)
47ca377
Fixes #12659

(cherry picked from commit 9a444d1)
@patchback patchback Bot mentioned this pull request Aug 30, 2024
[PR #12716/9a444d11 backport][8.3.x] Fix: pytest >=8.1.0 displays no diff for AssertionError with `--impor… #12755
Merged
nicoddemus pushed a commit that referenced this pull request Aug 30, 2024
@patchback @dongfangtianyu
Fix assertion rewriting with importlib mode (#12716) (#12755)
bf379f4
Fixes #12659

(cherry picked from commit 9a444d1)

Co-authored-by: dongfangtianyu <[email protected]>
@dongfangtianyu
dongfangtianyu deleted the bugfix-12659 branch September 9, 2024 09:29
@dongfangtianyu dongfangtianyu mentioned this pull request Dec 12, 2024
fix: Resolved an ImportError crash when using --import-mode=importlib #13053
Merged
nicoddemus added a commit that referenced this pull request Dec 12, 2024
@dongfangtianyu @nicoddemus
Fix ImportError crash when using --import-mode=importlib (#13053)
28e1e25
Regression in #12716  

In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead.  

**Trigger conditions:**  
1. `/cow/moo/moo.py` exists (a file and directory with the same name).  
2. `/cow/moo/test_moo.py` exists (test case resides in the directory).  

When pytest loads test files in `importlib` mode, it continues recursive loading upward:  
- When loading `cow.moo`, it should return a namespace but unexpectedly returns a module.  
- When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace.  

**Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue)  
- `main.py`: Reproduces the error.  
- `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`.  

**Context:**
#12592 (comment)
#12592 (comment)


---------

Co-authored-by: Bruno Oliveira <[email protected]>
patchback Bot pushed a commit that referenced this pull request Dec 12, 2024
@dongfangtianyu @nicoddemus @patchback
Fix ImportError crash when using --import-mode=importlib (#13053)
1c9e8a3
Regression in #12716

In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead.

**Trigger conditions:**
1. `/cow/moo/moo.py` exists (a file and directory with the same name).
2. `/cow/moo/test_moo.py` exists (test case resides in the directory).

When pytest loads test files in `importlib` mode, it continues recursive loading upward:
- When loading `cow.moo`, it should return a namespace but unexpectedly returns a module.
- When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace.

**Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue)
- `main.py`: Reproduces the error.
- `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`.

**Context:**
#12592 (comment)
#12592 (comment)

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 28e1e25)
@patchback patchback Bot mentioned this pull request Dec 12, 2024
[PR #13053/28e1e25a backport][8.3.x] fix: Resolved an ImportError crash when using --import-mode=importlib #13054
Merged
nicoddemus pushed a commit that referenced this pull request Dec 12, 2024
@patchback @dongfangtianyu
Fix ImportError crash when using --import-mode=importlib (#13053) (…
4e7af35
…#13054)

Regression in #12716

In short: `PathFinder.find_spec` received the argument `/cow/moo` but loaded `/cow/moo/moo.py` instead.

**Trigger conditions:**
1. `/cow/moo/moo.py` exists (a file and directory with the same name).
2. `/cow/moo/test_moo.py` exists (test case resides in the directory).

When pytest loads test files in `importlib` mode, it continues recursive loading upward:
- When loading `cow.moo`, it should return a namespace but unexpectedly returns a module.
- When loading `cow.moo.moo`, it should return a module but unexpectedly returns a namespace.

**Complete example:** [[GitHub repository](https://github.com/dongfangtianyu/pytest_importlib_issue)](https://github.com/dongfangtianyu/pytest_importlib_issue)
- `main.py`: Reproduces the error.
- `debug.py`: Demonstrates the behavior of `PathFinder.find_spec`.

**Context:**
#12592 (comment)
#12592 (comment)

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 28e1e25)

Co-authored-by: dongfangtianyu <[email protected]>
This was referenced Apr 10, 2026
pathlib: Fix module path used when using importlib with namespaces #12313
Merged
--import-mode=importlib breaks assertion rewriting #12044
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nicoddemus nicoddemus nicoddemus approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

pytest >=8.1.1 displays no diff for AssertionError with --import-mode=importlib

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@dongfangtianyu @nicoddemus
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.