Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Introspecting function signatures

by Corion (Pope)
on Mar 06, 2021 at 14:51 UTC ( #11129193=note: print w/replies, xml ) Need Help??


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

Is there a reason why they need to be available as parameters at all? These fixtures could just be global variables, couldn't they?

  • Comment on Re^5: Introspecting function signatures

Replies are listed 'Best First'.
Re^6: Introspecting function signatures
by szabgab (Priest) on Mar 06, 2021 at 19:57 UTC
    They could, but this way they are localized to the function, they go out of scope after the function is done and one test will not impact another test.

      I would use local for that:

      { local $tempdir = '/tmp/foo'; test_someting(); }

      Most likely you need to wrap all these test_something(...) function calls anyway with your code, and that's a good place to set up the localized test fixtures as well.

      I'm wondering a bit how you plan to handle one such function calling another function. Should the fixtures be recreated or not?

      sub test_someting2( $tempdir, $aValue ) { if( $^O !~ /mswin/i ) { test_someting("$tempdir/$aValue"); } else { test_someting("$tempdir\\$aValue"); }; }
        You would not call test functions by yourself, the system would do. In this specific case you'd use File::Spec anyway.

        What is interesting in this case might be how to skip tests. I think the usual SKIP would work inside the test functions, but there might be some way to mark test functions to be skipped conditionally. Pytest uses "decorators" for this.

        @pytest.mark.skipif(sys.platform != 'darwin', reason="Mac tests") def test_func(): ...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2021-04-13 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?