[py-dev] py.test api - Running tests in a module object?
holger krekel
holger at merlinux.eu
Thu Aug 5 23:28:23 CEST 2010
On Thu, Aug 05, 2010 at 14:24 -0700, Sridhar Ratnakumar wrote:
> On 8/5/2010 2:06 PM, holger krekel wrote:
>> 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).
>
> Hmm, __file__ is a workaround, but it seems to work fine for my use
> case. I was just wondering if an API was exposed.
>
> I am happy with __file__ for now.
What do you think about automating this lookup and allowing
py.test.cmdline.main([module])
maybe that's enough?
best,
holger
More information about the Pytest-dev
mailing list