Hi Frederik,

On Tue, Oct 20, 2009 at 20:02 +0100, Frederik Dohr wrote:
> In a brief conversation with Holger today, I confessed that for a long 
> time I couldn't bring myself to properly read up on funcargs.
> While I appreciate the obvious efforts that have gone into creating the 
> comprehensive documentation*, it did seem just a little intimidating. 
> (Also, I generally prefer reading code to reading prose.)

It contains many examples and also a reference for the API. 
I consider splitting the two aspects.

> Anyway, I finally played around a bit with funcargs, and it actually 
> turned out to be fairly easy to get started:
>      http://gist.github.com/214495
> 
> While those code samples are certainly not perfect, I figured it might 
> be useful to share this naive quickstart approach with the class.
> I'll need to do more reading to assess whether or how this fits into the 
> existing documentation though.

nice for understand setup - but i wonder.  If py.test did some
basic logging that shows which user code is invoked when (e.g. 
test function, setup functions, funcarg factories, plugin or
conftest hooks ...) it would make such help-examples smaller and
more focused.  With "user code" i mean code invoked from 
the test tool.

Below is a try at explaining funcargs from a "read-source" perspective. 

best & thanks for the feedback,
holger



A minimal example for using a funcarg begins like this::

    def test_logging(tmpdir):
        p = tmpdir.mkdir("example")

The 'tmpdir' is an empty temporary directory unique per test function. 
Let's use another funcarg to monkey-patch an environment variable 
and then do a test that our application honours it::

    def test_logging(tmpdir, monkeypatch):
        p = tmpdir.join("logfile")
        monkeypatch.setenv('LOGFILE', p)
        ... call app which does logging ... 
        s = p.read()
        assert "startup..." in s

Both the tmpdir and the monkeypatch values are created from 
their respective funcarg factory.  Here is the monkeypatch 
funcarg factory:

http://bitbucket.org/hpk42/py-trunk/src/d9645744d8a5/_py/test/plugin/pytest_monkeypatch.py

_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to