Professional Documents
Culture Documents
Python Qualis
Python Qualis
Which of the following are the unit testing packages availabale in Python?
All of those mentioned
Which type of testing is done when one of your existing functions stop working?
regression testing
m
er as
The discipline of writing tests first and then writing development code is known
co
as ____________.
eH w
Test Driven development
o.
Which type of testing is performed to check if a program is behaving as
rs e
expected?
ou urc
acceptance testing
Software Testing
aC s
================================================================================
v i y re
===============================================
1. Which of the following is a valid doctest?
def add(x,y):
"""Returns sum of two numbers.
>>>add(5,6)
ed d
13
ar stu
"""
return x+y
"""
print(x)
print()
print(y)
print()
print(x*y)
Which of the following doctest correctly tests it's functionality?
>>> sample_func(6,7)
6
<BLANKLINE>
7
<BLANKLINE.
42
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
#doctest: +NORMALIZE_WHITESPACE
m
def mul(x, y):
er as
"""Multiplies two given numbers and returns the product.
co
>>> mul(6, 7)
eH w
42
>>> mul(-8, 7)
o.
>>> -56 rs e
"""
ou urc
return x * y
What is the expected output when you run the doctests using below command?
7.Which of the following doctest directive is used to ignore part of the result?
#doctest: +ELLIPSIS
8.Which of the following special attribute can be used to access a doc string in
a program?
ed d
__doc__
ar stu
What is the parent class from which a Test class has to be derived for running
it with unittest?
unittest.TestCase
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
Which of the following method is used to catch exceptions in a test, with
unittest?
assertRaises
A single test module contains only one Test Class. State true or false.
False
How many tests of sample_module.py shown below, are successfully passed, when
run with unittest?
import unittest
class SampleTestClass(unittest.TestCase):
def test_sample1(self):
self.assertRaises(TypeError, pow, 2, '4')
m
er as
def test_sample2(self):
co
self.assertRaises(Exception, max, [7, 8, '4'])
eH w
def test_sample3(self):
o.
self.assertRaises(ValueError, int, 'hello')
rs e
0
ou urc
How many tests are run, when below code is tested using unittest
import unittest
o
aC s
def test_sample1():
v i y re
assert 3 == 3
class SampleTestClass(unittest.TestCase):
ed d
ar stu
def test_sample2(self):
self.assertEqual(3, 3)
1
unittest.main
What is the purpose of using self.id in tests, while working with unittest?
self.id returns the name of the method
How many tests are run, when below code is tested using unittest
import unittest
class SampleTestClass(unittest.TestCase):
def sample_test1(self):
self.assertEqual('HELLO', 'hello'.upper())
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
def test_sample2(self):
self.assertEqual(3*3, 9)
1
Which of the following method is used to check equality of two lists in a test,
with unitest?
assertListEqual
Which of the following command is execute to run all the test cases present in a
project folder using unittest?
python -m unittest discover
Which of the following decorator need to be used while working with setUpClass
and tearDownClass fixtures?
@classmethod
Which of the following are the module level fixtures of unittest framework?
setUpModule, tearDownModule
m
assertRegexpMatches
er as
co
Which is the expected output of below code, when run using command python -m
eH w
unittest sample_module.py
o.
import unittest rs e
ou urc
class SampleTestClass(unittest.TestCase):
def setUpClass(cls):
print('Entering Test Class')
o
aC s
def tearDownClass(cls):
v i y re
def test_sample1(self):
self.assertEqual(3*3, 9)
The test run fails
ed d
ar stu
Which of the following decorator is used to assign user defined setup and tear
down functions to a test function, while using nose?
@with_setup
nose can recognise tests which are not part of a Test class, derived from a
Parent class. State True or False
True
How many tests of sample_module.py shown below, are successfully passed, when
run with nose?
class SampleTestClass:
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
@raises(TypeError)
def test_sample1(self):
pow(2, '4')
@raises(Execption)
def test_sample2(self):
max([7, 8, '4'])
@raises(Exception)
def test_sample3(self):
int('hello')
1
How many tests are run, when below code is tested using nose?
import unittest
def test_sample1():
assert 3 == 3
class SampleTestClass(unittest.TestCase):
m
er as
co
def test_sample2(self):
eH w
self.assertEqual(3, 3)
0
o.
rs e
Which of the following package is required for generating test reports in html
ou urc
format using nose?
nose-htmloutput
True
aC s
v i y re
@timed
ar stu
True
Th
Which of the following option is used to generate test report in xml using nose?
--with-xunit
================================================================================
======================================
Which of the following commands run only one test case, present in
sample_module.py using pytest?
py.test sample_module.py::TestCase1::test_method1
Which of the following command is used to discover all tests in a project and
execute them using pytest?
py.test
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
Which of the following are the function level fixtures available in pytest?
setup_function,teardown_function
How many tests are run, when below code is tested using pytest
import unittest
def test_sample1():
assert 3 == 3
class SampleTestClass(unittest.TestCase):
def test_sample2(self):
self.assertEqual(3, 3)
2
pytest is capable of discovering and running tests written in unittest and nose.
State true or false.
True
m
pytest is available as a part of Python standard library. State true or false.
er as
False
co
eH w
Which of the following option is used to generate Junit style test report in xml
using pytest?
o.
--junitxml rs e
ou urc
Which of the following decorator is used to skip a test unconditionally, with
pytest?
@pytest.mark.skip
o
aC s
v i y re
ed d
ar stu
sh is
Th
This study source was downloaded by 100000790328255 from CourseHero.com on 06-27-2021 13:10:38 GMT -05:00
https://www.coursehero.com/file/38323060/Python-Qualistxt/
Powered by TCPDF (www.tcpdf.org)