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
Copy file name to clipboardExpand all lines: _drafts/2015-01-01-automated-testing-maya-plugin-development.md
+36-2
Original file line number
Diff line number
Diff line change
@@ -32,15 +32,49 @@ Another big goal was to require as little alt-tabbing as possible; having to swi
32
32
33
33
* Run Maya from Eclipse (more on that later);
34
34
* Run tests from Eclipse;
35
-
* Route all outputs to single console in IDE;
35
+
* Route all outputs back to Eclipse;
36
+
* Eliminate any need to switch to Maya window at all - be it reloading a plugin, setting some required options for debugging or inspecting a problem.
36
37
37
38
Ideally this would allow me to just sit in Eclipse and perform the whole development cycle in one tool.
38
39
39
40
## The setup in action
40
41
42
+
So this is where I am now. It's not really a one-click solution yet, but comfortable enough for me not to worry at this point.
41
43
42
-
*TODO: describe current setup in action*
44
+
### Running tests
43
45
46
+
The typical development session would start with running the whole set of tests. First, let's fire up Maya, there's a shortcut in IDE prepared for that; Maya quietly starts in the background, gets configured with all sorts of specific options just for this project, and starts listening for test launches.
47
+
48
+
Then, I execute the whole test suite. After it completes, I get this:
49
+

50
+
51
+
The console on the left is test execution script, which is mostly just shows test summary. The console on the right is Maya: it shows both C++ `cout`s and Python `print`s, and for each test being performed, the separator is put so I can see where one test ends and another begins, if any troubleshooting is needed.
52
+
53
+
If any test fails, the output would similar to this, with a convenient hyperlink to exact place in the code, being another benefit of doing everything in one tool:
There's no obvious way of "run all tests that you find" from inside Maya, things like [Nose](http://pythontesting.net/framework/nose/nose-introduction/) don't quite work; my solution is to use a highly simplified version of Nose approach, by going through all of modules and finding any test class. I do it with a `testsAll.py` in root test package with this:
59
+
60
+
{% highlight python %}
61
+
for root, dirds, files in os.walk(os.path.dirname(__file__)):
for _,c in inspect.getmembers(module, inspect.isclass):
70
+
if isTestsClass(c):
71
+
decorateTestMethods(c)
72
+
globals()[c.__name__.replace(".","_")] = c
73
+
{% endhighlight %}
74
+
75
+
Basically, after imported, `testsAll` module will have imported all tests classes that it finds in subpackages. `decorateTestMethods` adds some additional behaviour like printing test name in the log before each test.
76
+
77
+
Having this `testsAll` module means that I can use `unittest.TestLoader().loadTestsFromModule` to programmatically load all of my tests into one big suite and run it inside Maya, removing the need of command line tool for test discovery.
0 commit comments