[TIP] running tests from pytest.main

holger krekel holger at merlinux.eu
Tue Jun 26 00:48:40 PDT 2012

On Mon, Jun 25, 2012 at 14:52 -0400, Pella,Chris wrote:
> We are invoking pytest using pytest.main from a custom functional test framework we are layering on top of pytest. It creates a global test configuration dictionary based on some command line switches and some config file data.  I was trying to prevent the global config dictionary from being re-initialized and making it a singleton by doing this:
> if "config" not in dir(sys.modules[__name__]):
>                 config = {}
>                 ....

Why are you going through the sys.modules indirection instead of just doing:

    # contained in some module
    config = {}


If this is done in a module, "config" automatically is a singleton because
all imported Python modules are singletons (i.e. a given module is only
imported once usually).

If i am missing the point - could you provide a little reproducable example
and the pytest.main() invocations so that we can reproduce the problem?


> For some reason, when pytest is in control the above test of the sys.modules dict for the "config" name fails and the config dictionary is reinitialized and my config state is lost.  Oddly, we tried something similar on a colleagues machine using a python 2.6 ( I am using 2.7) and we didn't have that problem.
> Any ideas what could be happening? I find it a bit hard to debug because when pytest is in control on my machine it seems that I can't interact with the eclipse console after a breakpoint is hit.
> Chris
> The information contained in this electronic mail transmission 
> may be privileged and confidential, and therefore, protected 
> from disclosure. If you have received this communication in 
> error, please notify us immediately by replying to this 
> message and deleting it from your computer without copying 
> or disclosing it.

> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python

More information about the testing-in-python mailing list