[py-dev] funcarg name clash / conftest load behaviour

holger krekel holger at merlinux.eu
Fri Jun 25 12:05:36 CEST 2010


On Fri, Jun 25, 2010 at 11:44 +0200, Frank Hempel wrote:
> Am 25.06.2010 10:55, schrieb holger krekel:
> >> There is just one little thing left where i'm not sure what the benefit
> >> is in it. Consider the dir structure as meant in the last mails:
> >>
> >>     a/conftest.py
> >>     b/conftest.py
> >>
> >> If py.test is started from within the "a"-directory not only the
> >> conftest.py's of parent directories of "a" are loaded (as stated in the
> >> docs), also the conftest.py of the "b"-directory is loaded. I
> >> intuitively wouldn't consider "b" a parent of "a". Also the tests from
> >> "b" are not run of course. Does it makes sense to load "b"'s conftest.py
> >> too in this situation?
> > 
> > I agree it's a bit suprising. I'll explain why also to clarify it for myself :) 
> > 
> > * py.test sees the command line arg b/test_hello.py 
> > * it performs collection starting from the directory where 'b' is contained, call it ROOTDIR
> > * collecting ROOTDIR will collect all matching subdirs and files, so 'a' and 'b'
> > * [HERE] collecting the 'b' subdir will consult b/conftest.py to allow it to influence the 
> >   directory collection objects (it will call the pytest_collect_directory(...) hook to be precise)
> > * after all subdirs/files have been collected the one matching the name 'b' is dived into 
> > * ...
> 
> This process I was expecting when calling "py.test" (without arguments
> or with 'b/test_hello.py') from the ROOTDIR, as i think in your
> explaination you meant having py.test being called from ROOTDIR because
> the argument 'b/test_hello.py' you mentioned has 'b/' in it, right?.

I understand the confusion but indeed, i really meant 

    py.test b/test_hello.py 

will cause a collection of the ROOTDIR (containing 'b' and 'a'). 
py.test always collects from the root now matter how you call it. 
Otherwise collection customizations would not work uniformly. 
If you call py.test --collectonly you can see the collection result, btw. 

> ...
> if both conftest.py's have a pytest_configure and pytest_unconfigure,
> they will be called in this order:
> 
> configure of b
> configure of a
> unconfigure of a
> unconfigure of b
> 
> I agree that both 'a' and 'b' should be inspected when calling py.test
> from ROOTDIR, but when calling it within 'a' or 'b'...?

I understand your surprise which is why i told the background story 
and how i'd like to fix it. 
 
> ...i hope i don't bother you if i misunderstood your explaination (sorry
> in that case). but that you wrote "* py.test sees the command line arg
> b/test_hello.py" made me wonder whether you misunderstood me in the way
> that you thought i meant calling py.test from ROOTDIR.

you are welcome and thanks for trying to clarify. 
best,
holger



More information about the Pytest-dev mailing list