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

holger krekel holger at merlinux.eu
Fri Jun 25 10:55:03 CEST 2010


Hi Frank, 

On Fri, Jun 25, 2010 at 10:18 +0200, Frank Hempel wrote:
> Hi Holger,
> 
> thank you for the immediate reply.
> 
> Am 24.06.2010 16:40, schrieb holger krekel:
> > Are you using the latest 1.3.1 version?  It is meant to call the funcarg
> 
> Shame on me. I used 1.0.2.
> Indeed with 1.3.1 the nearest funcarg factories are called. Perfect.

good. 
 
> 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 
* ...

I think [HERE] is the issue: we could say that a conftest.py cannot
determine the directory collection object of its containing directory (only
of the subdirs) so for collecting 'b' the conftest.py would not need to be loaded. 
It's an edge case and so far i have been wary to change it for backward-compat 
reasons. 

However, i'd like to try to get rid of the py.test.collect.Directory subclass customization 
possibility alltogether and rather provide a simple hook which directly implements directory 
collection, it would simplify internal code and as a side effect remove the surprise you encountered. 
(because no attempt to collect anything under 'b' would be made and thus no a/conftest.py consulted 
when calling py.test on 'a')

best,
holger



More information about the Pytest-dev mailing list