No, but I used the equivalent in Lua. I was under the impression that no solution handled preprocessor macros, but this thread corrected me. I might do a follow-up post on this.
I spent two years using and then administering two RT servers.
I arrived with effectively no real PERL knowledge but a high level of Linux sysadmin competency
I hugely enjoyed working with the system. It was productive, flexible, and never gave me unexplained errors.
Even scripting on the perl api was an excellent experience.
Moreover the devs were extremely helpful in their irc channel (circa 2014-2016 at least) and walked me through a manual upgrade caused by the previous admin customizing the database schema in an unsafe way
For those of you using argparse I recommend looking at configargparse. A drop in replacement which adds environment variable support (similar to click) and config file support
I've wrestled with this problem several times. My conclusion was mocks are just fine, but this is a wart in that there isn't "one way to do it"
For the most part I can get by with one rule: always mock the module.
with mock.patch('os.listdir'):
will always work, even if it doesn't accomplish what you want.
with mock.patch('mymodule.os.listdir')
will fail if that module does not explicitly import os and instead does something like from os import listdir (perhaps because a later dev did not realize importing os directly was actually a requirement for the test and changed the code).
The rule is not perfect though. In the above case, the error will actually be
ImportError: No module named os
This can be fixed with e.g.,
assert hasattr(module, 'os'), "os module is not explicitly imported"
as a preamble to your test but ... it is not perfect by any means.
I don't understand what you mean by "will always work, even if it doesn't accomplish what you want." Mocking os.listdir will be useless if your product code's imports don't match it. How is this "one rule" to use?
The os module ships with python, so the function call mocking os.listdir will always succeed even if the code being tested does not use os.listdir
By mocking mymodule.os.listdir you add a requirement that mymodule actually import the os module and take advantage of mock.patch failing loudly if it does not.
Even Apple had the famous episode of releasing an update that bricked phones with replacement parts that weren't sanctioned. They reversed it after much public outcry.
For less common hardware the situation is just as bad. Agriculture equipment has been a pain point for many to get repaired, as the parts are much harder to find and the limited number of certified repair shops can be pressured to stop servicing equipment deemed end of life by the manufacturer
For the uninitiated this basically cranked your ability to uninstall windows components up to 11, allowing you to strip out IE and and get windows humming along quite well on antiquated hardware.
https://pypi.org/project/ConfigArgParse/