[PYTHON] Installation and easy usage of pytest

Since I used pytest to implement the test code in python, I will summarize the introduction method and the minimum usage.

environment Mac OSX Python 3.7.7, pytest-6.1.2, py-1.9.0, pluggy-0.13.1

How to install pytest (installation)

Terminal


$ pip install pytest

This completes the installation.

file organization

.test/
├── A
│   └── test_a.py
└── B
    └── test_b.py (If you want to execute them all at once, make sure that the file name is unique. ()

import os
import sys
sys.path.append(os.getcwd())  #pytest sys the current directory.If you want to read the file in the current directory because it is not added to path, import os,Specified with import sys

def test_a():
    assert 6 == multiplication(2, 3)

def multiplication(x, y):
    return x * y

Test code execution method

When executing by folder

Terminal


$ pytest test/A

You can also execute it for multiple folders at once from the upper level.

Terminal


$ pytest test

When executing by file

Terminal


$ pytest test/A/test_a.py

Or move the directory

Terminal


$ pytest test_a.py

But it's okay.

If you run it and pass the test, it will look like this. (Green notation) スクリーンショット 2021-01-12 14.38.08.png

Recommended Posts

Installation and easy usage of pytest
Pre-processing and post-processing of pytest
Source installation and installation of Python
Installation of SciPy and matplotlib (Python)
Easy installation of OpenCV on RaspberryPi 3+
Easy usage memo of Anaconda (conda)
Installation procedure + usage of "virtualenv" and "pythonz" in Mountain Lion environment
Installation of Visual studio code and installation of python
[Note] [PyTorch] From installation to easy usage
Easy introduction of python3 series and OpenCV3
BESS Development Memo # 01: BESS Installation and Basic Usage
Installation of Anaconda3
Installation of CentOS 8
pytest usage summary
RDKit easy installation
Installation of Python3 and Flask [Environment construction summary]
Organize the super-basic usage of Autotools and pkg-config
[Python] Class type and usage of datetime module
Easy installation and launch of Jupyter Notebook using Docker (also supports nbextensions and Scala)
Aim for easy installation of OpenCv and Cuda using JetPack (NVIDIA SDK Manager) from Nvidia
Installation of OpenMDAO (version 1.7.1)
jupyter and pandas installation
Summary of pyenv usage
Basic usage of flask-classy
Python --Explanation and usage summary of the top 24 packages
Basic usage of Jinja2
Easy partial download of mp4 with python and youtube-dl!
Usage of Python locals ()
[Linux] Installation of nvm
Basic usage of SQLAlchemy
Installation of Python 3.3 rc1
Installation of Docker on Raspberry Pi and L Chika
Installation of matplotlib (Python 3.3.2)
Easy usage memo of OpenStack Swift API using swiftclient
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
Installation of dlib, cv2
[Package management] Installation destination and internal processing of apt and pip
[Python] Correct usage of map
Problems of liars and honesty
Mechanism of pyenv and virtualenv
Docker Easy Installation Procedure (CentOS)
Basic usage of PySimple GUI
Reinforcement learning 2 Installation of chainerrl
Combination of recursion and generator
Combination of anyenv and direnv
Explanation and implementation of SocialFoceModel
Python installation and basic grammar
Convenient usage summary of Flask
Installation of ChEMBL webresource client
Django installation and operation check
(Minimal) usage of django logger
Use and integration of "Shodan"
Problems of liars and honesty
Basic usage of Pandas Summary
Sample usage of Python pickle
Scrapy installation troubles and solutions
Occurrence and resolution of tensorflow.python.framework.errors_impl.FailedPreconditionError
Tomcat installation and autostart settings
Basic usage of Python f-string
[Python] Correct usage of join
Comparison of Apex and Lamvery