LoginSignup
6
9

More than 5 years have passed since last update.

Python で unittest して CI する

Last updated at Posted at 2016-12-13

前提

  • Python 3.5
  • unittest
  • Travis CI
  • GitHub Public Repository

ディレクトリ構成

project/
├── src/
│   └── module/
│       ├── __init__.py
│       └── add.py
├── test/
│   ├── module/
│   │   ├── __init__.py
│   │   └── test_add.py
│   └── __init__.py
└── .travis.yml

内容

モジュールを書きます.

project/src/module/__init__.py
project/src/module/add.py
def add(a, b):
    return a + b

おまじないを書きます.

project/test/__init__.py
import sys

sys.path.append('src')

テストを書きます (ファイル名は test_*.py).

project/test/module/__init__.py
project/test/module/test_add.py
import unittest

from module.add import add


class TestAdd(unittest.TestCase):
    def test_add(self):
        self.assertEqual(add(1, 2), 3)


if __name__ == '__main__':
    unittest.main()

CI してもらいます.

project/.travis.yml
language: python
python: 3.5
script: python -m unittest discover
6
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
9