[py-dev] py.test api - Running tests in a module object?

holger krekel holger at merlinux.eu
Thu Aug 5 23:06:52 CEST 2010


Hi Sridhar, 

On Thu, Aug 05, 2010 at 13:46 -0700, Sridhar Ratnakumar wrote:
> I am trying to run py.test on a given module object dynamically.
> 
>      mod = __import__('company.foo.somemod')
>      py.test.run(mod)
> 
> A quick glance in the py.test source doesn't seem like a trivial thing. 
> IPython introspection did not give me any clue either.
> 
> Is there a way to do this at all? I did try 
> py.test.cmdline.main(['...']), but that accepts only file path, not the 
> Python module object itself.

there currently is no direct support for running tests in python modules. 
py.test basically always starts from the file system. Does it help you
to try to fish the file from somemod.__file__ and pass this to cmdline.main()? 
You only expect it to collect tests of a single module, right? 
I guess we could add some more direct support for this if
you continue to have the need (please create an issue if so). 

cheers,
holger



More information about the Pytest-dev mailing list