UnitTesting
UnitTesting copied to clipboard
Using other test frameworks besides unittest?
I just installed UnitTesting last night and am really happy with it so far. In my Python code outside of Sublime plugins, I like to use other frameworks that build on top of unittest like pytest or Parameterized to reduce the amount of boilerplate test code.
Is it possible to use other frameworks besides unittest inside Sublime with UnitTesting?
I figured this may be possible by adding the pip package go dependencies.json for my Sublime plugin, but I haven't found support for something like dev-only dependencies yet. I'm wondering if you've had this use case before?
I don’t think Package Control supports dev-only dependencies. You'll need to clone the specific modules and make them available to your computer locally (or remotely if you are working with CI services). Also note that unittest.discover is used to find testcases. Not all frameworks also honor using similar kind of discovery.
Hmm good points. I'll give it a shot and see how it goes. Thanks for the quick reply.
FWIW, for pytest: Sublime uses ancient python33 so last supported version range for pytest is 3.2.x.
What I tried:
> pip install -t vendor pytest==3.2
# Somewhere in the code
import site
site.addsitedir(SublimePackagesPath / 'UnitTesting' / 'vendor')
Invoking pytest basically means import pytest; pytest.main(...). So this is still a black-box and they don't provide any information or support for a fine grained, customized loader. Note that import pytest already has side-effects, and pytest.main only works once per python process (bc it has global side effects). a) Use multiproceesing. 👎 bc it's not supported in Sublime, b) manually cleanup the import cache (sys.modules-fu probably, but I didn't test that) so that python re-imports everything.
Other problems:
# Sublime-surprise
>>> import sys
>>> sys.argv
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'argv'
but pytest expects it naturally
...