Skip to content

Differences in how modules are imported between running pytest on a directory or a file #11588

Answered by bluetech
Kodiologist asked this question in Q&A
Discussion options

You must be logged in to vote

The reason is this: pytest uses "assertion rewriting" as a way to implement its assert magic. It rewrites test modules at the AST level and loads the rewritten AST instead of the original. The python import system doesn't have an "AST transform pipeline" concept, only "find" (path -> module spec) and "load" (module spec -> module object). So the flow is this (pytest part in [...]):

path -> module spec -> hy -> module object -> [path -> ast -> ast rewrite -> module object]

The "[path -> ast]" (ast.parse()) part can't work because the file is hy syntax not python syntax. There is no way to go "module object -> ast" without reparsing the file.

OK so pytest's assertion rewriting feature seemi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Kodiologist
Comment options

@bluetech
Comment options

Answer selected by Kodiologist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants