How to write and run unit tests for a Python plugin?
Hello,
I have written a very simple Python extension plugin, which runs and "works" (as far as designed).
However, I have been unable to write functional unit tests - when I run the tests with the standard JUnit test runner, the tests fail in the call to `PythonSdkType.getInstance`, by hitting the `assert false` line in `SdkType.findInstance`. (Meaning that apparently, the Python SDK was not loaded, or maybe it was a classloader issue?).
How should I write or configure the tests so that the Python SDK is loaded before entering the first test?
I have used code inspired from `PyTestCase` and `PyLightProjectDescriptor`, without success. Are there utility test classes, similar to LightCodeInsightFixtureTestCase, but for a plugin that depends on Python PSI elements?
Thank you in advance.
Please sign in to leave a comment.
Hi Jean,
Actually, PyTestCase is intended to test Python PSI elements as well.
if you want to write a test that involves Python SDK then you might want to take a look at Env tests that test the code for different Python interpreters.
Look at PythonDebuggerTest for example.
Thank you Dmitry for the information.
Is there a library that packages the PyTestCase class? I cannot find it in the python.jar library, and I would rather not try to compile the library or copy the class wholesale.
However, I feel that I am missing some setup for the Python plugin classes to be usable in my tests (as mentioned, I get a failure as soon as I call PythonSdkType.getInstance()). Is there a setup that should be done in the JUnit configuration, in some global set up code, or in the test runner?