environment Mac OSX Python 3.7.7, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
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. ()
test
(eg test_integration.py, test_unit.py)test
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
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)