New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin Asset: reset method pointer when parsing a new class. #3665
Plugin Asset: reset method pointer when parsing a new class. #3665
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3665 +/- ##
==========================================
- Coverage 69.69% 69.64% -0.05%
==========================================
Files 135 135
Lines 17332 17341 +9
==========================================
- Hits 12079 12078 -1
- Misses 5253 5263 +10
Continue to review full report at Codecov.
|
avocado/plugins/assets.py
Outdated
| @@ -135,6 +135,9 @@ def visit_ClassDef(self, node): # pylint: disable=C0103 | |||
| if self.klass and node.name != self.klass: | |||
| return | |||
|
|
|||
| # if we are parsing a new class, reset the curret method pointer | |||
| if self.current_klass != node.name: | |||
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.
Doesn't it make more sense to always reset the current_method when setting current_klass? My reasoning is that the ClassDef will always be visited before the FunctionDef, no?
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.
Works too, with less caution. I have removed the if and force pushed.
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.
I double-checked just to make sure, and as far as I could test, ClassDef executes before FunctionDef and only once for each class.
If there are multiple test classes in the same file, the current method pointer is not reset when parsing the next test class in the file. This may cause a KeyError exception when there is an assignment in a class attribute in the following class. Signed-off-by: Willian Rampazzo <willianr@redhat.com>
a29b9a5
to
f9b4dc7
Compare
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.
LGTM, thanks!
If there are multiple test classes in the same file, the current method pointer is not reset when parsing the next test class in the file. This may cause a KeyError exception when there is an assignment in a class attribute in the following class.
Signed-off-by: Willian Rampazzo willianr@redhat.com