"dependency injection" is how this is called in the case of pytest, maybe it is not a generic term

Well, I think Dependency Injection is a very well-known generic term, and heavily used in statically typed languages (e.g. C++, Java, C#) though it seems to be much less popular in dynamic languages, such as Perl and Python, as indicated here:

Dependency injection (DI) is regarded with suspicion in the Python world ... The standard way to do things is to declare our dependency implicitly by simply importing it, and then if we ever need to change it for tests, we can monkeypatch, as is Right and True in dynamic languages.
A reply to this SO question states that "A MonkeyPatch is a piece of Python code which extends or modifies other code at runtime (typically at startup)".

In frustration, I searched all of docs.pytest.org and the only reference I found to dependency injection was:

consider using pytest’s more powerful fixture mechanism which leverages the concept of dependency injection
So please put me out of my misery by pointing us at the pytest dependency injection documentation you saw.

BTW, I've happily used Dependency Injection for years in C++ (but not Perl). In C++, you define an interface argument to the class constructor, then, in the unit test, inject a mock object (an instance of a class inheriting from the interface class), while injecting an instance of the real class (also inheriting from the same interface class) in production code. ... Hmmmm, I see I liked it so much that I explicitly singled it out as "perhaps the most important design pattern in making code easier to test" at Effective Automated Testing.

Update: See this reply for a nice example of using Dependency Injection in Perl by chromatic.

Monkey Patching References


In reply to Re^7: Introspecting function signatures (Dependency Injection and Monkey Patching) by eyepopslikeamosquito
in thread Introspecting function signatures by szabgab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.