This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decorations on functions are not re-applied after rewriting their assertions. This is because a function like @foo def a(): pass is (effectively) sugar for def a(): pass a = foo(a) However, rewrite_assertion only extracts the function from the recompiled code. To include the decorations, we have to execute the code and extract the function from the globals. However, this presents a problem, since the decorator must be in scope when executing the code. We could use the module's __dict__, but it's possible that the decorator is redefined between when it is applied to the function and when the module finishes execution: def foo(f): return f @foo def a(): pass foo = 5 This will load properly, but would fail if we tried to execute code for the function with the module's final __dict__. We have similar problems for constructs like for i in range(4): def _(i=i): return i To really be correct here, we have to rewrite assertions when importing the module. This is actually much simpler than the existing strategy (as can be seen by the negative diffstat). It does result in a behavioral change where all assertions in a test module are rewritten instead of just those in tests. This patch does not handle cases like import b_test assert 1 == 2 because if a_test is imported first, then it will import b_test with the regular importer and the assertions will not be rewritten. To fix this correctly, we need to replace the loader to add an exec hook which applies only to test modules. This patch does not implement this and so I have marked this patch RFC. However, if such a scenario does not occur, this is more than enough to get hypothesis working.
- Loading branch information
Showing
5 changed files
with
44 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters