Feature testing with pytest

Introduction to Testing in Python

Alexander Levin

Data Scientist

What is a feature test

Feature

  • a software system functionality.
  • satisfies a particular user's requirement.

Features

  • are wider that units.
  • End-user can use features.

Feature testing

  • software testing method.
  • verify the behavior of a specific feature.
  • Examples:
    • Data distribution check
    • Report preparation
Introduction to Testing in Python

Units vs. features: personal computer

Units:

  • Each individual button
  • Pixels on the screen
  • LED diodes
  • Blocks on the disk

Features:

  • Keyboard
  • Screen
  • Illumination
  • File system
Introduction to Testing in Python

Why do we use feature tests

Feature testing helps:

  • To test things at the scope of the user interaction with a system.

The scope is wider than units:

  • One unit does not work - does not mean the feature is NOT OK.

Vice versa:

  • All units work as expected - does not mean the feature is OK.
Introduction to Testing in Python

Feature test example: setup

Setup and defining the feature code:

# Setup
import pandas as pd
import pytest

df = pd.read_csv('laptops.csv')

# Filter feature
def filter_data_by_manuf(df, manufacturer_name):
    filtered_df = df\
        [df["Manufacturer"] == manufacturer_name]
    return filtered_df
Introduction to Testing in Python

Feature test example: testing

Testing code:

# Feature test function
def test_unique():
    manuf_name = 'Apple'
    filtered = filter_data_by_manuf(df, manuf_name)
    assert filtered\
        ['Manufacturer'].nunique() == 1
    assert filtered\
        ['Manufacturer'].unique() == [manuf_name]
Introduction to Testing in Python

Summary

Feature testing - software testing method, allows to verify the behavior of a specific feature.

Features are wider that units:

  • If a button is a unit, then the keyboard is a feature.

Feature testing helps to ensure that users get exactly what they expect.

To create feature tests one has to create test cases.

The key to design feature tests - to understand what the features are in a specific system.

Introduction to Testing in Python

Let's practice!

Introduction to Testing in Python

Preparing Video For Download...