Book Image

Hands-On Enterprise Application Development with Python

By : Saurabh Badhwar
Book Image

Hands-On Enterprise Application Development with Python

By: Saurabh Badhwar

Overview of this book

Dynamically typed languages like Python are continuously improving. With the addition of exciting new features and a wide selection of modern libraries and frameworks, Python has emerged as an ideal language for developing enterprise applications. Hands-On Enterprise Application Development with Python will show you how to build effective applications that are stable, secure, and easily scalable. The book is a detailed guide to building an end-to-end enterprise-grade application in Python. You will learn how to effectively implement Python features and design patterns that will positively impact your application lifecycle. The book also covers advanced concurrency techniques that will help you build a RESTful application with an optimized frontend. Given that security and stability are the foundation for an enterprise application, you’ll be trained on effective testing, performance analysis, and security practices, and understand how to embed them in your codebase during the initial phase. You’ll also be guided in how to move on from a monolithic architecture to one that is service oriented, leveraging microservices and serverless deployment techniques. By the end of the book, you will have become proficient at building efficient enterprise applications in Python.
Table of Contents (24 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

Chapter 8


Answer 1

The major difference between a unit test and a functional test is the scope of testing, as described in the following:

  • Unit test: A unit test usually focuses on the testing of individual components in a software that could be factored to a single function or a method of a class
  • Functional test: Functional tests are also known as integration tests and usually test a specific functionality of the system that may encompass the interaction of multiple components with each other, along with their interaction with the external environment, such as database systems.

Answer 2

A test suite is a collection of test cases that needs to be run on a specific program. Writing a test suite using Python's unittest library is quite easy to achieve. For example, if you've written a few test cases, such as TestTextInput, TestTextUppercase, and TestTextEncode, we can combine them into a test suite by using the following code snippet:

import texttest # Module containing our text related test cases
import unittest

# Create a test loader
loader = unittest.TestLoader()

# Create a test suite
suite = unittest.TestSuite()

# Add tests to a suite
suite.addTests(loader.loadTestsFromModule(texttests)

Answer 3

The purpose of fixtures inside Pytest is to provide a fixed and stable environment over which the tests cases can execute. These fixtures are responsible for initializing the environment by setting up the required variables or interfaces that may be required for a test to execute.

Another advantage of using a fixture is its reusability, which allows the same fixture to be used for multiple tests without any issue.

Answer 4

The fixture scopes in Pytest describe how often a fixture will be called. The fixtures have a lot of different scopes that can be applied to them, as shown in the following:

  • Function scope: Fixture is run once per test
  • Class scope: Fixture is run once per class
  • Module scope: Fixture is run once per module
  • Session scope: Fixture is run once per test session