Python package development notes

Directory tree

python


bash-3.2$ tree
.
├── hoge
│   ├── Hoge.py
│   └── __init__.py
├── setup.py
└── test
    ├── TestHoge.py
    └── __init__.py

--Put the package source in ./hoge --Put the unit test code in ./test --Prepare init.py for each (the contents can be empty) --Python recognizes the "file itself" or "contains init.py files in subdirectories" located in each directory of sys.path as packages to be imported.

setup.py

I'm sorry ...

setup.py


from setuptools import setup, find_packages



setup(
    name = "hoge",
    version = "0.1",
    packages = find_packages(),
    test_suite = 'test'
)

Unit test code

Use unittest.

TestHoge.py


import unittest
from hoge import Hoge


class TestPiyo(unittest.TestCase):
    def setUp(self):
        self.obj = Hoge.Piyo()

    def test_one(self):
        self.assertEqual(1, self.obj.one())

    def test_two(self):
        self.assertEqual("two", self.obj.two())

Run unit tests

Develop Hoge.py properly,

python


python setup.py test

Then the unit test is executed.

Recommended Posts

Python package development notes
Python ipaddress package notes
Python scraping notes
Python study notes _000
Python learning notes
Python beginner notes
Python study notes_006
python C ++ notes
Python study notes _005
Python grammar notes
Python Library notes
python personal notes
python pandas notes
Python study notes_001
python learning notes
Python3.4 installation notes
Blender 2.82 or later + python development environment notes
missingintegers python personal notes
Python test package memo
Python development environment construction
python decorator usage notes
[Personal notes] Python, Django
About Python development environment
Python Pickle format notes
[Python] pytest-mock Usage notes
First Python miscellaneous notes
python2.7 development environment construction
Matlab => Python migration notes
Python package manager comparison
Framework development in Python
Development environment in Python
Notes around Python3 assignments
Notes using Python subprocesses
Anaconda Package Management Notes
Python try / except notes
Bluemix Python Microservices Development
python> Link> PyUserInput package |
Python framework bottle notes
Slackbot development in Python
Notes on creating a python development environment on macOS Catalina
Python notes using perl-ternary operator
O'Reilly python3 Primer Learning Notes
Web scraping notes in python3
Python package management in IntelliJ
Python notes to forget soon
python * args, ** kwargs Usage notes
Python + Kivy development on Windows
Python notes using perl-special variables
Python 處 處 regular expression Notes
Python Tkinter notes (for myself)
[Python] Notes on data analysis
Organize your Python development environment
Python data analysis learning notes
Notes on installing Python on Mac
[ev3dev × Python] Build ev3dev development environment
Python development in Visual Studio 2017
[MEMO] [Development environment construction] Python
[For organizing] Python development environment
Get Evernote notes in Python
Python development in Visual Studio
Notes on installing Python on CentOS