Best Python code snippet using pytest
test_collection_util.py
Source:test_collection_util.py
...74 )75 def test_get_selector_error(self):76 with self.assertRaises(TypeError):77 get_selector(42)78 def test_isiterable(self):79 def generator():80 yield81 self.assertTrue(isiterable(''))82 self.assertTrue(isiterable(()))83 self.assertTrue(isiterable([]))84 self.assertTrue(isiterable(generator()))85 self.assertFalse(isiterable(None))86 self.assertFalse(isiterable(42))87 self.assertFalse(isiterable(object()))88 def test_ismapping(self):89 self.assertTrue(ismapping({}))90 self.assertFalse(ismapping([]))91 def test_is_sequence_not_str(self):92 self.assertTrue(is_sequence_not_str(()))93 self.assertTrue(is_sequence_not_str([]))94 self.assertFalse(is_sequence_not_str({}))...
iterutils.py
Source:iterutils.py
...26import warnings27from kitchen.iterutils import isiterable as _isiterable28warnings.warn('fedora.iterutils is deprecated. Use kitchen.iterutils'29 ' instead', DeprecationWarning, stacklevel=2)30def isiterable(obj, include_string=True):31 '''*Deprecated* Use kitchen.iterutils.isiterable instead.32 .. warning::33 kitchen.iterutils.isiterable uses False as the default value for34 :attr:`include_string` instead of True.35 Check whether an object is an iterable.36 :arg obj: Object to test whether it is an iterable37 :include_string: If True (default), if `obj` is a str or unicode this38 function will return True. If set to False, strings and unicodes will39 cause this function to return False.40 :returns: True if `obj` is iterable, otherwise False.41 '''42 warnings.warn('fedora.iterutils.isiterable is deprecated, use'43 ' kitchen.iterutils.isiterable instead', DeprecationWarning,44 stacklevel=2)45 return _isiterable(obj, include_string)...
test_iterutils.py
Source:test_iterutils.py
...25 True,26 0,27 1.1,28 )29 def test_isiterable(self):30 for item in self.iterable_data:31 tools.ok_(iterutils.isiterable(item) == True)32 for item in self.non_iterable_data:33 tools.ok_(iterutils.isiterable(item) == False)34 # strings35 tools.ok_(iterutils.isiterable(b'a', include_string=True) == True)36 tools.ok_(iterutils.isiterable(b'a', include_string=False) == False)37 tools.ok_(iterutils.isiterable(b'a') == False)38 tools.ok_(iterutils.isiterable('a', include_string=True) == True)39 tools.ok_(iterutils.isiterable('a', include_string=False) == False)40 tools.ok_(iterutils.isiterable('a') == False)41 def test_iterate(self):42 iterutils.iterate(None)43 for item in self.non_iterable_data:44 tools.ok_(list(iterutils.iterate(item)) == [item])45 for item in self.iterable_data[:-1]:46 tools.ok_(list(iterutils.iterate(item)) == list(item))47 # iter() is exhausted after use so we have to test separately48 tools.ok_(list(iterutils.iterate(iter([1, 2, 3]))) == [1, 2, 3])49 # strings50 tools.ok_(list(iterutils.iterate(b'abc')) == [b'abc'])51 tools.eq_(list(iterutils.iterate(b'abc', include_string=True)), [ord(b'a'), ord(b'b'), ord(b'c')])52 tools.ok_(list(iterutils.iterate('abc')) == ['abc'])...
vo20_iter.py
Source:vo20_iter.py
1#/usr/bin/python32# coding:utf-83from collections import Iterable4#*************************************************************************5# å¤æä¸ä¸ªå¯¹è±¡æ¯å¦æ¯Iterable对象6#*************************************************************************7def isIterable(e):8 return isinstance(e, Iterable)9print('Listå±äºå¯è¿ä»£å¯¹è±¡:', isIterable([])) # list10print('dictå±äºå¯è¿ä»£å¯¹è±¡:', isIterable({})) # dict11print('setå±äºå¯è¿ä»£å¯¹è±¡:', isIterable(set(['a', 'b', 'c']))) # set12print('tupleå±äºå¯è¿ä»£å¯¹è±¡:', isIterable(('U', 'x', 'e', 'i'))) # tuple13print('strå±äºå¯è¿ä»£å¯¹è±¡:', isIterable('abc')) # str14print('generatorå±äºå¯è¿ä»£å¯¹è±¡:', isIterable(x**x for x in range(10))) # generator15print('numberå±äºå¯è¿ä»£å¯¹è±¡:', isIterable(100)) # number16#*************************************************************************17# æ们已ç»ç¥éï¼å¯ä»¥ç´æ¥ä½ç¨äºfor循ç¯çæ°æ®ç±»åæ以ä¸å ç§ï¼18# ä¸ç±»æ¯éåæ°æ®ç±»åï¼å¦listãtupleãdictãsetãstrçï¼19# ä¸ç±»æ¯generatorï¼å
æ¬çæå¨å带yieldçgenerator functionã20# è¿äºå¯ä»¥ç´æ¥ä½ç¨äºfor循ç¯ç对象ç»ç§°ä¸ºå¯è¿ä»£å¯¹è±¡ï¼Iterableã...
Looking for an in-depth tutorial around pytest? LambdaTest covers the detailed pytest tutorial that has everything related to the pytest, from setting up the pytest framework to automation testing. Delve deeper into pytest testing by exploring advanced use cases like parallel testing, pytest fixtures, parameterization, executing multiple test cases from a single file, and more.
Skim our below pytest tutorial playlist to get started with automation testing using the pytest framework.
https://www.youtube.com/playlist?list=PLZMWkkQEwOPlcGgDmHl8KkXKeLF83XlrP
Get 100 minutes of automation test minutes FREE!!