Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^12: Introspecting function signatures

by szabgab (Priest)
on Mar 07, 2021 at 21:13 UTC ( #11129298=note: print w/replies, xml ) Need Help??

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

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 } }

Replies are listed 'Best First'.
Re^13: Introspecting function signatures
by LanX (Sage) on Mar 07, 2021 at 21:31 UTC
    My take on it
    • if a test is called it should have fresh fixtures
    • you need to know which variables need to be initialized as fixtures
    • you need to know which tests use which fixtures
    I think this can be done with a combination of PadWalker to scan the sub, and variable attributes to initialize them as fixture objects.

    Unfortunately I'll be several days AFK, so I can't show you a POC.

    Anyway I think you are rather inclined to do the PyWay and I've probably missed some edge cases.

    (Tho you already mentioned py-decorators, and that's attributes in Perl.)

    Feel free to ignore my thoughts and do as you like ...

    Hope this helped nonetheless... :)

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2022-08-08 22:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found