Python Qualis
Python Qualis
State
true or false.
False
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
The discipline of writing tests first and then writing development code is known as
____________.
Test Driven development
The process of evaluating a software with an intent to determine if it has met the
specified requirements is known as __________.
Software Testing
===================================================================================
============================================
1. Which of the following is a valid doctest?
def add(x,y):
"""Returns sum of two numbers.
>>>add(5,6)
13
"""
return x+y
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?
__doc__
9.Which of the following doctest directive is used for not considering or executing
a specific doctest?
#doctest: +SKIP
What is the parent class from which a Test class has to be derived for running it
with unittest?
unittest.TestCase
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')
def test_sample2(self):
self.assertRaises(Exception, max, [7, 8, '4'])
def test_sample3(self):
self.assertRaises(ValueError, int, 'hello')
0
How many tests are run, when below code is tested using unittest
import unittest
def test_sample1():
assert 3 == 3
class SampleTestClass(unittest.TestCase):
def test_sample2(self):
self.assertEqual(3, 3)
1
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())
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
Which is the expected output of below code, when run using command python -m
unittest sample_module.py
import unittest
class SampleTestClass(unittest.TestCase):
def setUpClass(cls):
print('Entering Test Class')
def tearDownClass(cls):
print('Exiting Test Class')
def test_sample1(self):
self.assertEqual(3*3, 9)
The test run fails
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:
@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):
def test_sample2(self):
self.assertEqual(3, 3)
0
Which of the following package is required for generating test reports in html
format using nose?
nose-htmloutput
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 decorator is used to transform a user defined function into
a fixture using pytest?
@pytest.fixture
Which of the following command is used to discover all tests in a project and
execute them using pytest?
py.test
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
Which of the following option is used to generate Junit style test report in xml
using pytest?
--junitxml