2

I am writing a Python module that specifies a set of entry_points, so other host modules can discover a new piece of functionality. I am following the setuptools approach specified at the official documentation.

As an example, the snippet below shows a contribution through sample.contribution named hello-world which points to timmins.hello_world attribute.

[options.entry_points]
sample.contribution =
    hello-world = timmins:hello_world

Let's suppose the host plugin defines a method like the following for loading sample.contributions extensions.

def load_contributions():
   ...

What I want to do is to write a test that ensures the entry_point is properly loaded by the host module. At this moment, the only way of testing such entry_point loading is through building a wheel and pip-install it. Once installed, the entry_point can be loaded sucessfully.

So, my question is ... Is there any way of adding the specified entry_points at setup.py (or setup.cfg) so they can be loaded during the tests execution? That is, a test for the module that defines the entry_point that returns the contributions when calling the load_contributions method

josandres
  • 317
  • 1
  • 11
  • Not sure it is worth testing this. If it were me I would assume that it is tested in _setuptools_ already. -- Which leads me to think that maybe it would be worth looking at _setuptools_'s own code base and test suite to see how they do test such things and draw inspiration from it. – sinoroc Jan 23 '21 at 11:07
  • Isn't interesting to test if a plugin implements host-defined extension point properly? I think it's worht testing it before reaching a production environment and not loading a plugin. – josandres Jan 25 '21 at 06:43
  • 1
    Ah, I guess I had misunderstood the question. Yes, you can use tox, since it always installs the project properly before running the commands (the test suite). So if installed correctly then the entry points definitely should be available as well. – sinoroc Jan 25 '21 at 17:53
  • @josandres, I also have the same issue. Did you find your solution? – Ashok Rayal Jun 25 '21 at 13:30
  • @AshokRayal go ahed using tox. You can define custom testenv where both host library and extension plugins can be installed. Works for me at least :D – josandres Jun 29 '21 at 07:42

1 Answers1

2

Maybe using tox for executing a set of test commands is the right choice. This approach installs the developed module into a virtual environment, and so its entry_points are loaded when invoking a command.

josandres
  • 317
  • 1
  • 11