Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^9: Introspecting function signatures

by LanX (Saint)
on Mar 07, 2021 at 13:48 UTC ( [id://11129268]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Introspecting function signatures
in thread Introspecting function signatures

you'll also have the benefit of putting repeated fixtures in the closure.

compare this Pytest discussion about the resulting boilerplate

https://stackoverflow.com/questions/63292928/add-pytest-fixtures-to-a-test-class-using-dependency-injection

you might want to avoid importing their flows. :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^9: Introspecting function signatures

Replies are listed 'Best First'.
Re^10: Introspecting function signatures
by szabgab (Priest) on Mar 07, 2021 at 14:14 UTC
    I am not sure what closure are you talking about here, but the best would be if you could show a code snippet how you think it would be used in a test? And yes, it would be nice to avoid the linked problem.
      > show a code snippet how you think it would be used in a test?

      pseudocode, because I don't know your project sufficiently well

      { my $fixture_A = temdir(); # fixture in closure sub test1 ($fixture_B) { # no need to repeat A # uses fixture A and B } sub test2 ($fixture_C) { # no need to repeat A # uses fixture A and B } }

      NB: I use "closure" in the original sense, it's the hull with "enclosed vars" not the enclosed sub.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I am sort-of giving up the dependency injection idea, at least for the first pass, as the end result could be achieved by calling the function that returns the fixture.

        In your example I wonder what kind of fixture could be such common feature without making the tests accidentally impacting each other. First thought that $fixture_A must be some resource that is not changed during the tests or that we can be sure that they change it in an independent way. (eg. in the case of a tempdir this could mean one of them creates file1.txt the other one creates file2.txt.)

        However this sound a bit risky as the tests might accidentally step on each others toes.

        However this way it is the decision of the author of the test.

        { my $fixture_A = temdir(); # fixture in closure sub test1 { my $fixture_B = get_fixture_b(); # uses fixture A and B } sub test2 { my $fixture_C = get_fixture_c(); # uses fixture A and B } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129268]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found