You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently experimenting with mamba for testing a flask application. However, I encountered a weired bug during test writing. When the app instance is imported directly into the spec file, I can use context mangers, for instance app.test_client(), without any problems. When importing the whole module, then the AST parsing seems to crash. See the attached code for a MWE and more details.
spec.py:
frommambaimportafter, before, context, description, itimportutilsfromutilsimportappwithdescription('Bug') asself:
withcontext('when importing instance from module directly'):
withit('works'):
withapp.test_client():
passwithcontext('when importing the whole module'):
withit('fails to deal with context managers'):
withutils.app.test_client():
pass
utils.py:
fromflaskimportFlaskapp=Flask(__name__)
$ mamba spec.py
Traceback (most recent call last):
File "/usr/local/bin/mamba", line 9, in <module>
load_entry_point('mamba==0.9.3', 'console_scripts', 'mamba')()
File "/usr/local/lib/python3.5/dist-packages/mamba/cli.py", line 18, in main
runner.run()
File "/usr/local/lib/python3.5/dist-packages/mamba/runners.py", line 29, in run
modules = self.example_collector.modules()
File "/usr/local/lib/python3.5/dist-packages/mamba/example_collector.py", line 25, in modules
with self._load_module_from(path) as module:
File "/usr/lib/python3.5/contextlib.py", line 59, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.5/dist-packages/mamba/example_collector.py", line 57, in _load_module_from
yield self._module_from_ast(name, path)
File "/usr/local/lib/python3.5/dist-packages/mamba/example_collector.py", line 60, in _module_from_ast
tree = self._parse_and_transform_ast(path)
File "/usr/local/lib/python3.5/dist-packages/mamba/example_collector.py", line 83, in _parse_and_transform_ast
tree = self._node_transformer.visit(tree)
File "/usr/lib/python3.5/ast.py", line 245, in visit
return visitor(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 18, in visit_Module
super(TransformToSpecsNodeTransformer, self).generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/usr/lib/python3.5/ast.py", line 245, in visit
return visitor(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 28, in visit_With
super(TransformToSpecsNodeTransformer, self).generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/usr/lib/python3.5/ast.py", line 245, in visit
return visitor(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 28, in visit_With
super(TransformToSpecsNodeTransformer, self).generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/usr/lib/python3.5/ast.py", line 245, in visit
return visitor(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 28, in visit_With
super(TransformToSpecsNodeTransformer, self).generic_visit(node)
File "/usr/lib/python3.5/ast.py", line 300, in generic_visit
value = self.visit(value)
File "/usr/lib/python3.5/ast.py", line 245, in visit
return visitor(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 30, in visit_With
name = self._get_name(node)
File "/usr/local/lib/python3.5/dist-packages/mamba/nodetransformers.py", line 49, in _get_name
return context_expr.func.value.id
AttributeError: 'Attribute' object has no attribute 'id'
The text was updated successfully, but these errors were encountered:
I am currently experimenting with mamba for testing a flask application. However, I encountered a weired bug during test writing. When the app instance is imported directly into the spec file, I can use context mangers, for instance
app.test_client()
, without any problems. When importing the whole module, then the AST parsing seems to crash. See the attached code for a MWE and more details.spec.py:
utils.py:
The text was updated successfully, but these errors were encountered: