I found in saucelabs example.py
file the following code snippet using the import new
module.
import new
# .. snip ..
def on_platforms(platforms):
def decorator(base_class):
module = sys.modules[base_class.__module__].__dict__
for i, platform in enumerate(platforms):
d = dict(base_class.__dict__)
d['desired_capabilities'] = platform
name = "%s_%s" % (base_class.__name__, i + 1)
module[name] = new.classobj(name, (base_class,), d)
return decorator
However reading the help(new)
shows that that module is deprecated. What is a non-depreciated way to do new.classobj(name, (base_class,), d)
The
type
keyword is a class. You can perform the above usingThis will return a class of name
name
with the tuple parameters of the base classbase_class
, initializing the member objects with thedict
d
.