summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2014-10-20 17:58:02 +0300
committerClaudiu Popa <pcmanticore@gmail.com>2014-10-20 17:58:02 +0300
commit1c5cab5ce9c6bf5c2a161748d03a5fa44a69e15e (patch)
tree66253119deaafa24c502204383c349725bfbf536
parent2e2d04b4c270f31c1a9883e9ae41bb2d4cbca3fe (diff)
downloadastroid-git-1c5cab5ce9c6bf5c2a161748d03a5fa44a69e15e.tar.gz
Add missing pytest plugin. Patch by Robbie Coomber.
This was added at some point in pylint-brain, but we lost the plugin after moving pylint-brain at last in astroid.
-rw-r--r--ChangeLog2
-rw-r--r--brain/py2pytest.py50
2 files changed, 52 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 4288d89c..e676e1a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,8 @@ Change log for the astroid package (used to be astng)
* Various speed improvements. Patch by Alex Munroe.
+ * Add pytest brain plugin. Patch by Robbie Coomber.
+
2014-08-24 -- 1.2.1
* Fix a crash occurred when inferring decorator call chain.
diff --git a/brain/py2pytest.py b/brain/py2pytest.py
new file mode 100644
index 00000000..b5537c09
--- /dev/null
+++ b/brain/py2pytest.py
@@ -0,0 +1,50 @@
+"""Astroid hooks for pytest."""
+
+from astroid import MANAGER
+from astroid import nodes
+from astroid.builder import AstroidBuilder
+
+
+MODULE_TRANSFORMS = {}
+
+
+def transform(module):
+ try:
+ tr = MODULE_TRANSFORMS[module.name]
+ except KeyError:
+ pass
+ else:
+ tr(module)
+
+
+def pytest_transform(module):
+ fake = AstroidBuilder(MANAGER).string_build('''
+
+try:
+ import _pytest.mark
+ import _pytest.recwarn
+ import _pytest.runner
+ import _pytest.python
+except ImportError:
+ pass
+else:
+ deprecated_call = _pytest.recwarn.deprecated_call
+ exit = _pytest.runner.exit
+ fail = _pytest.runner.fail
+ fixture = _pytest.python.fixture
+ importorskip = _pytest.runner.importorskip
+ mark = _pytest.mark.MarkGenerator()
+ raises = _pytest.python.raises
+ skip = _pytest.runner.skip
+ yield_fixture = _pytest.python.yield_fixture
+
+''')
+
+ for item_name, item in fake.locals.items():
+ module.locals[item_name] = item
+
+
+MODULE_TRANSFORMS['pytest'] = pytest_transform
+MODULE_TRANSFORMS['py.test'] = pytest_transform
+
+MANAGER.register_transform(nodes.Module, transform)