### Summary

Ansible devel sanity tests failing with error: packaging Python module unavailable; unable to validate the collection

### Issue Type

Bug Report

### Component Name

ansible sanity tests

### Ansible Version

```console
$ ansible devel
```


### Configuration

```console
$ ansible-config dump --only-changed
```


### OS / Environment

mac os

### Steps to Reproduce

<!--- Paste example playbooks or commands between quotes below -->
```yaml (paste below)

```
Ansible devel sanity tests is failing with `stderr: [WARNING]: packaging Python module unavailable; unable to validate collection`. Plz ref the below test failures:
[ansible-test-sanity-docker-devel](https://dashboard.zuul.ansible.com/t/ansible/build/ffc5d7c618a740bf9c783e15c2d14806)
[network-ee-sanity-tests](https://dashboard.zuul.ansible.com/t/ansible/build/b4ab02b51d76487b97356f3c6ffe76fe)

### Expected Results

Ansible sanity tests run without failure for `devel`

### Actual Results

```console
Ansible sanity tests fail for `devel`
```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct
"""Monitor sys.modules for unwanted changes, reverting any additions made to our own namespaces."""
        snapshot = sys.modules.copy()
        try:
            yield
        finally:
            check_sys_modules(path, snapshot, messages)
            for key in set(sys.modules.keys()) - set(snapshot.keys()):
                if is_name_in_namepace(key, ('ansible', 'ansible_collections')):
                    del sys.modules[key]  
    @contextlib.contextmanager
    def capture_output(capture):
        """Capture sys.stdout and sys.stderr.
        :type capture: Capture
        """
        old_stdout = sys.stdout
        old_stderr = sys.stderr
        sys.stdout = capture.stdout
        sys.stderr = capture.stderr
        
        for module in sys.modules.values():
            try:
                
                module.__warningregistry__.clear()
            except AttributeError:
                pass