Passed
Push — master ( 4fca22...42b5ce )
by Marcus
40s
created

PytestMayaPlugin   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pytest_sessionstart() 0 12 4
A pytest_sessionfinish() 0 6 2
1
"""
2
The runner launched pytest with either pytest from mayapy or from the system
3
python site-packages
4
"""
5
import os
6
import sys
7
8
try:
9
    import pytest
10
except ImportError:
11
    pytest_path = sys.argv[1]
12
    if pytest_path is not None:
13
        sys.path.append(os.path.dirname(pytest_path))
14
        import pytest
15
    else:
16
        raise ImportError
17
18
19
class PytestMayaPlugin(object):
20
21
    def pytest_sessionstart(self):
22
        import maya.standalone
23
        maya.standalone.initialize()
24
25
        # If testing a maya module make sure PYTHONPATH and sys.path are
26
        # identical
27
        realsyspath = [os.path.realpath(path) for path in sys.path]
28
        pythonpath = os.environ.get('PYTHONPATH', '')
29
        for p in pythonpath.split(os.pathsep):
30
            p = os.path.realpath(p)
31
            if p not in realsyspath:
32
                sys.path.insert(0, p)
33
34
    def pytest_sessionfinish(self):
35
        import maya.standalone
36
        from maya import cmds
37
        # Starting Maya 2016, we have to call uninitialize
38
        if float(cmds.about(v=True)) >= 2016.0:
39
            maya.standalone.uninitialize()
40
41
42
def main():
43
    pytest_args = sys.argv[2]
44
    pytest.main([pytest_args], plugins=[PytestMayaPlugin()])
45
46
47
if __name__ == '__main__':
48
    main()
49