# Using custom tests from custom filters

**URL:** <https://forum.ansible.com/t/using-custom-tests-from-custom-filters/38387>\
**Category:** Ansible Project\
**Created:** [August 29, 2023, 4:34pm UTC](https://forum.ansible.com/t/using-custom-tests-from-custom-filters/38387 "2023-08-29T16:34:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 29, 2023, 4:34pm UTC](https://forum.ansible.com/t/using-custom-tests-from-custom-filters/38387/1 "2023-08-29T16:34:07Z")

</div>

I have an application specific complex data structure and a custom test plugin for comparing them with varying criteria. Now I want to use that test in some custom filter plugin(s). What’s the canonical python way to use custom tests from custom filters?

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 31, 2023, 6:12pm UTC](https://forum.ansible.com/t/using-custom-tests-from-custom-filters/38387/2 "2023-08-31T18:12:01Z")

</div>

Maybe my question wasn’t clear. I have a project level **_custom test_** that lives in ./test\_plugins/tablinx.py relative to the root of our project. The test itself is called mw\_tab\_sch\_distinct, and it returns True if two compared dicts describe functionally different “schedules” (as per Tableau server definitions of schedules). “Functionally distinct” means we ignore fields like “name” which can be different without changing the timing of the schedule. Likewise we ignore the ordering of certain internal lists since a schedule definition containing [‘Monday’, ‘Wednesday’, ‘Friday’] and another containing [‘Wednesday’, ‘Friday’, ‘Monday’] are not distinct. Suffice to say, it’s nuanced.

I have another project level _ **custom filter** _ that lives in ./filter\_plugins/tablinx.py, also relative to the project root. The filter itself is called mw\_tab\_sch\_uniqcomb, and it accepts a list of Tableau “schedule” dicts, and returns two lists. The first list contains all the functionally distinct schedules from the input, while the second list contains zero or more lists each of which contains two or more functionally identical schedules from the input list.

All of this works, but only because the guts of the custom test plugin code is duplicated in the custom filter plugin. This is DIY-wrong beyond embarrassing. There must be a way to reference and use the custom tests contained within ./test\_plugins/tablinx.py from the custom filters sitting in ./filter\_plugins/tablinx.py.

Any suggestions would be greatly appreciated.
