# Making a collection compatible with core 2.19 and templating changes

**URL:** <https://forum.ansible.com/t/making-a-collection-compatible-with-core-2-19-and-templating-changes/41717>\
**Category:** Collection Development\
**Tags:** templating, collections, ansible-core\
**Created:** [April 14, 2025, 3:30pm UTC](https://forum.ansible.com/t/making-a-collection-compatible-with-core-2-19-and-templating-changes/41717 "2025-04-14T15:30:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [April 14, 2025, 3:40pm UTC](https://forum.ansible.com/t/making-a-collection-compatible-with-core-2-19-and-templating-changes/41717/2 "2025-04-14T15:40:29Z")

</div>

If your unit tests start failing because you mock module arguments like this:

```python
from ansible.module_utils import basic
args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
basic._ANSIBLE_ARGS = to_bytes(args)
... execute the module ...

```

This no longer works, you need to use the `ansible.module_utils.testing.patch_module_args()` context manager instead:

```python
from ansible.module_utils.testing import patch_module_args
with patch_module_args(args):
    ... execute the module ...

```

One way to handle this for both older and newer ansible-core versions is to create your own context manager:

```python
@contextlib.contextmanager
def set_module_args(args):
    """
    Context manager that sets module arguments for AnsibleModule
    """
    if '_ansible_remote_tmp' not in args:
        args['_ansible_remote_tmp'] = '/tmp'
    if '_ansible_keep_remote_files' not in args:
        args['_ansible_keep_remote_files'] = False

    try:
        from ansible.module_utils.testing import patch_module_args
    except ImportError:
        # Before data tagging support was merged, this was the way to go:
        from ansible.module_utils import basic
        serialized_args = to_bytes(json.dumps({'ANSIBLE_MODULE_ARGS': args}))
        with patch.object(basic, '_ANSIBLE_ARGS', serialized_args):
            yield
    else:
        # With data tagging support, we have a new helper for this:
        with patch_module_args(args):
            yield

```

Then you can always run:

```python
with set_module_args({...}):
    ... execute the module ...

```

---

_[View the full topic](https://forum.ansible.com/t/making-a-collection-compatible-with-core-2-19-and-templating-changes/41717)._
