Skip to main content

Test suite enhancement for testing plugins

Project description

PackTest

This module is designed to provide a strictly in-code implementation of MetaPathFinder that can be leveraged in unit testing in order to simulate an entry point being created, as would be loaded by importlib.metadata.entry_points() in Python 3.8+ or by importlib_metadata.entry_points() in earlier versions.

If there are requests, additional functionality aimed at testing plugin packages may be added in future releases.

Usage

import unittest
import packtest

class Test(unittest.TestCase):

    def test_me(self):
        # Could move some of this to be a test fixture instead
        
        # Finder on sys.meta_path
        finder = packtest.TestFinder()
        
        # Add it to sys.meta_path
        finder.register()
        
        # Create a package
        package = packtest.TestPackage("foobar")
        
        # Create entry points
        package.add_entry_point(
            # Equivalent to a module with the following in setup.cfg:
            # [options.entry_points]
            # myep.group = 
            #     foobar = myep.tests:test.attr  
            packtest.TestEntryPoint("foobar", "myep.group", "myep.tests", "test.attr")
        )

        package.add_entry_point(
            # Equivalent to a module with the following in setup.cfg:
            # [options.entry_points]
            # myep.group = 
            #     foobar2 = myep.tests:test.attr[bar]  
            packtest.TestEntryPoint("foobar2", "myep.group", "myep.tests", "test.attr", ["bar"])
        )
        finder.add_package(package)

        # ... do testsConsultationClassesIslandOfferings2
        
        # Call this to remove your foobar test package
        finder.remove_package(package)

        # Remove all packages
        finder.clear()
        
        # It is necessary to clean up sys.meta_path after your test case with this:
        finder.unregister()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pack_test-0.1.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page