CS Unit 4-1
CS Unit 4-1
SOLVING
Team python
Department of Computer Science & Engineering
PYTHON FOR COMPUTATIONAL
PROBLEM SOLVING
Unit-4:Testing
Team python
Department of Computer Science & Engineering
PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
Agenda
➢ Introduction.
➢ Pytest installation .
➢ File identification and test methods.
➢ How to run ?
➢ Assertion in pytest.
PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
Introduction
➢ Testing is a process by which one or more expected behaviors
and results from a piece of software are exercised and confirmed.
➢ Large set of tools and libraries are available in python library for automated testing.
➢ PyTest
➢ Unittest
➢ DocTest
➢ Nose2
➢ Testif
➢Very easy to start with because of its simple and easy syntax.
➢Can run tests in parallel.
➢Can run a specific test or a subset of tests
➢Automatically detect tests
➢Skip tests
➢Open source
PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
Pytest installation
➢ To run more than one but not all the files in the folder use py.test
<filename1><filename2><filename3> and so on.
py.test test_one.py test_example1.py
Assertions are expression that return the status either True or False based on the
condition .
Syntax
assert <condition>,<error message>
Examples
assert "corona" == "corona2020" is an assertion failure.
assert 2==2 is a successful assertion
assert True is a successful assertion
assert False is an assertion failure.
PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
Pytest first program
1.Create the new directory named “testing “or any other name and navigate into your
directory from the command line.
2.Create the file named “test_example1.py” and add the below code and save it.
import pytest
def func(x):
return x + 1
def test_answer():
assert func(2) == 3
PYTHON FOR COMPUTATIONAL PROBLEM SOLVING
References
1.docs.pytest.org.
THANK YOU
Team Python
Department of Computer Science and Engineering
*Chitra G M, Neeta Ann Jacob, Sangeetha R, Jeny Jijo,
Pushpa G ,Supreetha R ,Rachana B S.