[doc] Add import statement for xfail in tutorial#3628
[doc] Add import statement for xfail in tutorial#3628gppezzi wants to merge 1 commit intoreframe-hpc:developfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3628 +/- ##
========================================
Coverage 91.38% 91.38%
========================================
Files 62 62
Lines 13520 13520
========================================
Hits 12355 12355
Misses 1165 1165 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
It is strange that it requires import, I'll try to reproduce. |
I've just tried adding an xfail to a reference in the tutorial and the import was not required as expected. It is required though whey you would like to decorate a test to mark an expected failure, which is also expected. But this "xfail" is not a builtin it's in the decorators and simply doing |
There was a problem hiding this comment.
Now I've seen the PR where this has happened. This was expected, as well as my example's behaviour (adding xfail in the reference definition in the class body). This is what is happening:
- Builtin names are "imported" in the test class' namespace automatically during the test class construction. That's why they are all available in the class body and an explicit import is not required.
- When you try to use them (unprefixed) inside a test method (aka hook), which was the case of your PR, then Python will think the name refers to a local variable and will fail. In this case, using
self.xfailto refer to the already imported name at the class level or using an explicit import as you did will work.
This is a more general behaviour of the builtins, so I think we should mention this in the corresponding docs for the builtins, in general. There, I think we should mention that it is advisable to always import the builtins, since this helps IDEs too. When the test variables and parameters were initially introduced, their implementation was not so cleanly separated as it is now with the builtins package, so there was no way to actually import a builtin.
|
I moved this to 4.9.2, but we will need to redo the PR against |
I suggest to mention in the tutorial whether the
import xfailis needed or not.Question came while discussing this PR.
I read somewhere that builtins do not require import, but apparently it is needed for
xfail()and it may cause confusion for such a trivial issue.