The source code and slide for my talk about the subject: unittesing in python

Overview

PyTest Talk

This talk give you some ideals about the purpose of unittest? how to write good unittest? how to use pytest framework? and show you the basic unittest structure for your project - check my slide.

pytest_passing_tests

Folder Structure

.
├── demo-tests
│   ├── test_01.py
│   ├── test_02.py
│   ├── test_03.py
│   ├── test_04.py
│   └── test_05.py
├── function_to_tests
├── resources
│   ├── genres_and_15_best_of_films.csv
│   └── pytest_demo_running.gif
├── tests
│    └── test_basic.py
├── conftest.py
├── fixtures.py
├── README.md
├── requirements.txt
  • demo-tests: contains demo unittests for this talk (safety to ignore in your project )
  • function_to_tests: contains your functions which need to be tested
  • resources: contains static files for the unittest
  • tests: contains your real unittest in your project
  • conftest.py: the pytest will find all user's fixtures from here
  • fixture.py: defining your fixtures

Installation

$ pip install -r requirements.txt

Pytest Configs

$ pytest [option] test_file|test_folder

# -s (print all string output)
# -v (print names of individual tests as they run)
# -x (stop at first failure)
# -k (only run tests matching following keywords)

Run Unittest Demo

$ pytest pytest-demo/demo-tests

Reference

[1] Htorrence - PyData Unit Test Talk 2018

[2] Pluralsight - Intro To Pytest

[3] Pytest Framework

[4] pytest-sugar plugin

You might also like...
Obsei is a low code AI powered automation tool.
Obsei is a low code AI powered automation tool.

Obsei is a low code AI powered automation tool. It can be used in various business flows like social listening, AI based alerting, brand image analysis, comparative study and more .

A pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database
A pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database

This is a pytest plugin, that enables you to test your code that relies on a running PostgreSQL Database. It allows you to specify fixtures for PostgreSQL process and client.

A pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine
A pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine

pytest-elasticsearch What is this? This is a pytest plugin that enables you to test your code that relies on a running Elasticsearch search engine. It

This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database
This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database

This is a pytest plugin, that enables you to test your code that relies on a running MongoDB database. It allows you to specify fixtures for MongoDB process and client.

Pytest-typechecker - Pytest plugin to test how type checkers respond to code

pytest-typechecker this is a plugin for pytest that allows you to create tests t

It's a simple script to generate a mush on code forces, the script will accept the public problem urls only or polygon problems.

Codeforces-Sheet-Generator It's a simple script to generate a mushup on code forces, the script will accept the public problem urls only or polygon pr

A simple Python script I wrote that scrapes NASA's James Webb Space Telescope tracker website using Selenium and returns its current status and location.

A simple Python script I wrote that scrapes NASA's James Webb Space Telescope tracker website using Selenium and returns its current status and location.

Selenium-python but lighter: Helium is the best Python library for web automation.
Selenium-python but lighter: Helium is the best Python library for web automation.

Selenium-python but lighter: Helium Selenium-python is great for web automation. Helium makes it easier to use. For example: Under the hood, Helium fo

Pynguin, The PYthoN General UnIt Test geNerator is a test-generation tool for Python
Pynguin, The PYthoN General UnIt Test geNerator is a test-generation tool for Python

Pynguin, the PYthoN General UnIt test geNerator, is a tool that allows developers to generate unit tests automatically.

Owner
nguyenlm
Expressive Speech Synthesis | NLP | Generative Models | Speech Adaptation
nguyenlm
Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.

Mockoon Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source. It has been built wi

mockoon 4.4k Dec 30, 2022
RAT-el is an open source penetration test tool that allows you to take control of a windows machine.

To prevent RATel from being detected by antivirus, please do not upload the payload to TOTAL VIRUS. Each month I will test myself if the payload gets detected by antivirus. So you’ll have a photo every month to prove RAtel’s discretion.

null 218 Dec 16, 2022
hyppo is an open-source software package for multivariate hypothesis testing.

hyppo (HYPothesis Testing in PythOn, pronounced "Hippo") is an open-source software package for multivariate hypothesis testing.

neurodata 137 Dec 18, 2022
PacketPy is an open-source solution for stress testing network devices using different testing methods

PacketPy About PacketPy is an open-source solution for stress testing network devices using different testing methods. Currently, there are only two c

null 4 Sep 22, 2022
To automate the generation and validation tests of COSE/CBOR Codes and it's base45/2D Code representations

To automate the generation and validation tests of COSE/CBOR Codes and it's base45/2D Code representations, a lot of data has to be collected to ensure the variance of the tests. This respository was established to collect a lot of different test data and related test cases of different member states in a standardized manner. Each member state can generate a folder in this section.

null 160 Jul 25, 2022
Code coverage measurement for Python

Coverage.py Code coverage testing for Python. Coverage.py measures code coverage, typically during test execution. It uses the code analysis tools and

Ned Batchelder 2.3k Jan 4, 2023
A command-line tool and Python library and Pytest plugin for automated testing of RESTful APIs, with a simple, concise and flexible YAML-based syntax

1.0 Release See here for details about breaking changes with the upcoming 1.0 release: https://github.com/taverntesting/tavern/issues/495 Easier API t

null 909 Dec 15, 2022
automate the procedure of 403 response code bypass

403bypasser automate the procedure of 403 response code bypass Description i notice a lot of #bugbountytips describe how to bypass 403 response code s

smackerdodi2 40 Dec 16, 2022
py.test fixture for benchmarking code

Overview docs tests package A pytest fixture for benchmarking code. It will group the tests into rounds that are calibrated to the chosen timer. See c

Ionel Cristian Mărieș 1k Jan 3, 2023
Rerun pytest when your code changes

A simple watcher for pytest Overview pytest-watcher is a tool to automatically rerun pytest when your code changes. It looks for the following events:

Olzhas Arystanov 74 Dec 29, 2022