Best Python code snippet using nose
plugintest.py
Source:plugintest.py
...157 return warn_re.sub(r"\g<category>: \g<detail>", out)158def remove_timings(out):159 return re.sub(160 r"Ran (\d+ tests?) in [0-9.]+s", r"Ran \1 in ...s", out)161def munge_nose_output_for_doctest(out):162 """Modify nose output to make it easy to use in doctests."""163 out = remove_stack_traces(out)164 out = simplify_warnings(out)165 out = remove_timings(out)166 return out.strip()167def run(*arg, **kw):168 """169 Specialized version of nose.run for use inside of doctests that170 test test runs.171 This version of run() prints the result output to stdout. Before172 printing, the output is processed by replacing the timing173 information with an ellipsis (...), removing traceback stacks, and174 removing trailing whitespace.175 Use this version of run wherever you are writing a doctest that176 tests nose (or unittest) test result output.177 Note: do not use doctest: +ELLIPSIS when testing nose output,178 since ellipses ("test_foo ... ok") in your expected test runner179 output may match multiple lines of output, causing spurious test180 passes!181 """182 from nose import run183 from nose.config import Config184 from nose.plugins.manager import PluginManager185 buffer = StringIO()186 if 'config' not in kw:187 plugins = kw.pop('plugins', [])188 if isinstance(plugins, list):189 plugins = PluginManager(plugins=plugins)190 env = kw.pop('env', {})191 kw['config'] = Config(env=env, plugins=plugins)192 if 'argv' not in kw:193 kw['argv'] = ['nosetests', '-v']194 kw['config'].stream = buffer195 196 # Set up buffering so that all output goes to our buffer,197 # or warn user if deprecated behavior is active. If this is not198 # done, prints and warnings will either be out of place or199 # disappear.200 stderr = sys.stderr201 stdout = sys.stdout202 if kw.pop('buffer_all', False):203 sys.stdout = sys.stderr = buffer204 restore = True205 else:206 restore = False207 warn("The behavior of nose.plugins.plugintest.run() will change in "208 "the next release of nose. The current behavior does not "209 "correctly account for output to stdout and stderr. To enable "210 "correct behavior, use run_buffered() instead, or pass "211 "the keyword argument buffer_all=True to run().",212 DeprecationWarning, stacklevel=2)213 try:214 run(*arg, **kw)215 finally:216 if restore:217 sys.stderr = stderr218 sys.stdout = stdout219 out = buffer.getvalue()220 print munge_nose_output_for_doctest(out)221 222def run_buffered(*arg, **kw):223 kw['buffer_all'] = True224 run(*arg, **kw)225if __name__ == '__main__':226 import doctest...
fixt.py
Source:fixt.py
1import re2from nose.plugins.plugintest import munge_nose_output_for_doctest as _cleanup3remove_info = re.compile(4 r'^(root: )?INFO: Attempting to remove file at .+datastore.*$\n', re.MULTILINE)5ds_warn = re.compile(r'^(root: )?WARNING:.+Could not .+ datastore.+$\n', re.MULTILINE)6pil_warn = re.compile(r'(root: )?WARNING:.*PIL$\n', re.MULTILINE)7nose_capt_start = re.compile(8 r'^-------------------- >> begin captured logging << --------------------$\n', re.MULTILINE)9nose_capt_end = re.compile(10 r'^--------------------- >> end captured logging << ---------------------$\n', re.MULTILINE)11client = None12def cleanup(out):13 out = _cleanup(out)14 out = remove_warns(out)15 return out16def remove_warns(out):17 orig_out = out18 out = remove_info.sub('', out)19 out = ds_warn.sub('', out)20 out = pil_warn.sub('', out)21 if out != orig_out:22 # lazily replace nose's stdout capture,23 # in the case of log output.24 # fixme: probably a better way?25 out = nose_capt_start.sub('', out)26 out = nose_capt_end.sub('', out)...
multiprocess_fixtures.py
Source:multiprocess_fixtures.py
1import sys2import os3from nose.plugins.skip import SkipTest4from nose.plugins.multiprocess import MultiProcess5from nose.plugins.plugintest import munge_nose_output_for_doctest6_multiprocess_can_split_ = True7def setup_module():8 try:9 import multiprocessing10 if 'active' in MultiProcess.status:11 raise SkipTest("Multiprocess plugin is active. Skipping tests of "12 "plugin itself.")13 except ImportError:...
coverage_html_fixtures.py
Source:coverage_html_fixtures.py
1import sys2import os3from nose.plugins.skip import SkipTest4from nose.plugins.cover import Coverage5from nose.plugins.plugintest import munge_nose_output_for_doctest6_multiprocess_can_split_ = True7def setup_module():8 try:9 import coverage10 if 'active' in Coverage.status:11 raise SkipTest("Coverage plugin is active. Skipping tests of "12 "plugin itself.")13 except ImportError:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!