1 .. MediaGoblin Documentation
3 Written in 2013 by MediaGoblin contributors
5 To the extent possible under law, the author(s) have dedicated all
6 copyright and related and neighboring rights to this software to
7 the public domain worldwide. This software is distributed without
10 You should have received a copy of the CC0 Public Domain
11 Dedication along with this software. If not, see
12 <http://creativecommons.org/publicdomain/zero/1.0/>.
14 ==============================
15 Writing unit tests for plugins
16 ==============================
18 Here's a brief guide to writing unit tests for plugins. However, it
19 isn't really ideal. It also hasn't been well tested... yes, there's
22 Some notes: we're using py.test and WebTest for unit testing stuff.
25 My suggestion is to mime the behavior of `mediagoblin/tests/` and put
26 that in your own plugin, like `myplugin/tests/`. Copy over
27 `conftest.py` and `pytest.ini` to your tests directory, but possibly
28 change the `test_app` fixture to match your own tests' config needs.
35 def test_app(request):
38 mgoblin_config=pkg_resources.resource_filename(
39 'myplugin.tests', 'myplugin_mediagoblin.ini'))
41 In any test module in your tests directory you can then do::
43 def test_somethingorother(test_app):
47 And you'll get a MediaGoblin application wrapped in WebTest passed in
50 If your plugin needs to define multiple configuration setups, you can
51 actually set up multiple fixtures very easily for this. You can just
52 set up multiple fixtures with different names that point to different
53 configs and pass them in as that named argument.
55 To run the tests, from MediaGoblin's directory (make sure that your
56 plugin has been added to your MediaGoblin checkout's virtualenv!) do::
58 ./runtests.sh /path/to/myplugin/tests/
60 replacing `/path/to/myplugin/` with the actual path to your plugin.
62 NOTE: again, the above is untested, but it should probably work. If
63 you run into trouble, `contact us
64 <http://mediagoblin.org/pages/join.html>`_, preferably on IRC!