Skip to content

fix: replace co_filename with the correct filename when the file is moved - #14551

Closed
15r10nk wants to merge 1 commit into
pytest-dev:mainfrom
15r10nk:fix-co-filename-after-move
Closed

fix: replace co_filename with the correct filename when the file is moved#14551
15r10nk wants to merge 1 commit into
pytest-dev:mainfrom
15r10nk:fix-co-filename-after-move

Conversation

@15r10nk

@15r10nk 15r10nk commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

closes #14552

@15r10nk
15r10nk force-pushed the fix-co-filename-after-move branch from 535f80f to 44f84e0 Compare June 5, 2026 16:56
@15r10nk
15r10nk marked this pull request as ready for review June 6, 2026 04:04

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of patching we should treat it as stale

@15r10nk

15r10nk commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

the problem is that the filename is used by other tools which can cause all sorts of problems later on.

this was my original problem (the only way I found to make it work was to patch pytest) 15r10nk/inline-snapshot#371

cpython solves this problem in a similar way https://bugs.python.org/issue1180193

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Let it be compiled fresh instead of patching code objects

Else file content and runtime state diverge

@15r10nk

15r10nk commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

The state should not diverge because it is already checked by comparing the timestamps.

What I would not do is compiling it again AND storing the new version on disk. The cpython issue mentioned cases where the same file might be stored on the network and mounted under different locations. Rewriting the file might cause cycles where multiple PCs might rewrite the file again and again ... .

But not storing is also expensive because you would recompile it every time.

I think the best solution here is to patch the filename like cpython does it too.

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

as far as im concerned unless cpython itself provides a mapper for this - we as a testrunner (which is typically assumed to run in isolation) to recompile rather than managing mutated state

my oppinion is that for pytest its most likely fine to just recompile and ensure stuff is in sync

@15r10nk

15r10nk commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Ok, I will provide a different pr.

@15r10nk

15r10nk commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@RonnyPfannschmidt I created #14989. can you review it.

@15r10nk 15r10nk closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The old co_filename is used when test files/folders are moved

2 participants