Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write test-cases for python setuptools entry-points plugins

I built a python application (the "host" app) that defines a setuptools entry-point, so that it can be extended. Plugin-authors then have to add the following into their setup.py file:

setup(
    # ...
    entry_points = {
        'myapp.plugins': 
        ['plugin_1 = <foo.plugin.module>:<plugin-install-func>']
    }
)

In order to test my setup, i have to

  • build a dummy wheel-package,
  • use pip to install it,
  • append new package's folder into sys.path and invoke pkg_resources.working_set.add_entry(package_dir)[*],
  • only then i can check the expected behavior (run TCs),
  • use pip to uninstall the package, and
  • finally remove installed package folder from sys.path,

And a separate package is needed for each test-case, if different functionality must be validated.
This whole testing-rig is rather verbose and clumsy.

Is there a more elegant way to write test-cases for setuptools entry-point plugins?

[*] Note: Installing a wheels or using pip* in develop mode with pip install -e <plugin-package> would not activate the plugin on the same interpreter on Linux; or at least not without appending afterwards the package folder in sys.path. On Windows, the above problem exists only on develop mode.

like image 779
ankostis Avatar asked Dec 04 '17 01:12

ankostis


1 Answers

I had a same problem and resolved by a dirty hack to build and 'pip install' the plugin package to test, into a tox's environment and run tests in that environment.

  • a test script does dirty hack, that is, to build and install a wheel package and run tests: https://github.com/ssato/yamllint-plugin-example/blob/master/tests/test_plugin.sh
  • tox configuration: https://github.com/ssato/yamllint-plugin-example/blob/master/tox.ini
like image 130
Satoru SATOH Avatar answered Oct 15 '22 08:10

Satoru SATOH