How to use run_module_as_main method in Nose2

Best Python code snippet using nose2

test_runpy.py

Source:test_runpy.py Github

copy

Full Screen

...732 """733 )734 )735 self.assertSigInt([sys.executable, run_module], cwd=tmp)736 def test_pymain_run_file_runpy_run_module_as_main(self):737 tmp = self.ham.parent738 run_module_as_main = tmp / "run_module_as_main.py"739 run_module_as_main.write_text(740 textwrap.dedent(741 """\742 import runpy743 runpy._run_module_as_main("ham")744 """745 )746 )747 self.assertSigInt([sys.executable, run_module_as_main], cwd=tmp)748 def test_pymain_run_command_run_module(self):749 self.assertSigInt(750 [sys.executable, "-c", "import runpy; runpy.run_module('ham')"],751 cwd=self.ham.parent,752 )753 def test_pymain_run_command(self):754 self.assertSigInt([sys.executable, "-c", "import ham"], cwd=self.ham.parent)755 def test_pymain_run_stdin(self):756 self.assertSigInt([sys.executable], input="import ham", cwd=self.ham.parent)757 def test_pymain_run_module(self):...

Full Screen

Full Screen

__main__.py

Source:__main__.py Github

copy

Full Screen

...275 run_module_as_main = runpy._run_module_as_main276 except AttributeError:277 runpy.run_module(target, alter_sys=True)278 else:279 run_module_as_main(target, alter_argv=True)280281282def run_code():283 # Add current directory to path, like Python itself does for -c.284 sys.path.insert(0, '')285 code = compile(ptvsd.options.target, '<string>', 'exec')286 setup_connection()287 eval(code, {})288289290def attach_to_pid():291 def quoted_str(s):292 assert not isinstance(s, bytes)293 unescaped = set(chr(ch) for ch in range(32, 127)) - {'"', "'", '\\'} ...

Full Screen

Full Screen

cli.py

Source:cli.py Github

copy

Full Screen

...249 except AttributeError:250 log.warning("runpy._run_module_as_main is missing, falling back to run_module.")251 runpy.run_module(target, alter_sys=True)252 else:253 run_module_as_main(target, alter_argv=True)254255256def run_code():257 log.describe_environment("Pre-launch environment:")258 log.info("Running code:\n\n{0}", options.target)259260 # Add current directory to path, like Python itself does for -c.261 sys.path.insert(0, "")262 code = compile(options.target, "<string>", "exec")263264 setup_debug_server("-c")265 eval(code, {})266267 ...

Full Screen

Full Screen

_common.py

Source:_common.py Github

copy

Full Screen

...75 testf(util.safe_decode(cmd_stderr), stderr)76 def runIn(self, testdir, *args, **kw):77 return run_nose2(*args, cwd=testdir, **kw)78 def runModuleAsMain(self, testmodule, *args):79 return run_module_as_main(testmodule, *args)80class _FakeEventBase(object):81 """Baseclass for fake :class:`~nose2.events.Event`\s."""82 def __init__(self):83 self.handled = False84 self.version = '0.1'85 self.metadata = {}86class FakeHandleFileEvent(_FakeEventBase):87 """Fake HandleFileEvent."""88 def __init__(self, name):89 super(FakeHandleFileEvent, self).__init__()90 self.loader = Stub() # FIXME91 self.name = name92 self.path = os.path.split(name)[1]93 self.extraTests = []94class FakeStartTestEvent(_FakeEventBase):95 """Fake :class:`~nose2.events.StartTestEvent`."""96 def __init__(self, test):97 super(FakeStartTestEvent, self).__init__()98 self.test = test99 self.result = test.defaultTestResult()100 import time101 self.startTime = time.time()102class FakeLoadFromNameEvent(_FakeEventBase):103 """Fake :class:`~nose2.events.LoadFromNameEvent`."""104 def __init__(self, name):105 super(FakeLoadFromNameEvent, self).__init__()106 self.name = name107class FakeLoadFromNamesEvent(_FakeEventBase):108 """Fake :class:`~nose2.events.LoadFromNamesEvent`."""109 def __init__(self, names):110 super(FakeLoadFromNamesEvent, self).__init__()111 self.names = names112class FakeStartTestRunEvent(_FakeEventBase):113 """Fake :class:`~nose2.events.StartTestRunEvent`"""114 def __init__(self, runner=None, suite=None, result=None, startTime=None,115 executeTests=None):116 super(FakeStartTestRunEvent, self).__init__()117 self.suite = suite118 self.runner = runner119 self.result = result120 self.startTime = startTime121 self.executeTests = executeTests122class Stub(object):123 """Stub object for use in tests"""124 def __getattr__(self, attr):125 return Stub()126 def __call__(self, *arg, **kw):127 return Stub()128def support_file(*path_parts):129 return os.path.abspath(os.path.join(SUPPORT, *path_parts))130def run_nose2(*nose2_args, **nose2_kwargs):131 if 'cwd' in nose2_kwargs:132 cwd = nose2_kwargs.pop('cwd')133 if not os.path.isabs(cwd):134 nose2_kwargs['cwd'] = support_file(cwd)135 return NotReallyAProc(nose2_args, **nose2_kwargs)136def run_module_as_main(test_module, *args):137 if not os.path.isabs(test_module):138 test_module = support_file(test_module)139 return subprocess.Popen([sys.executable, test_module] + list(args),140 stdout=subprocess.PIPE, stderr=subprocess.PIPE)141class NotReallyAProc(object):142 def __init__(self, args, cwd=None, **kwargs):143 self.args = args144 self.chdir = cwd145 self.kwargs = kwargs146 self.result = None147 def __enter__(self):148 self._stdout = sys.__stdout__149 self._stderr = sys.__stderr__150 self.cwd = os.getcwd()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nose2 automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful