環境
- Python 3.6.3
- nose 1.3.7
- OS LinuxMint18.2(Ubuntu16.04LTS派生)
- pipenvで仮想環境を作っています
情況
testsというディレクトリに以下の三つのファイルがあります。
python
1# shared_module.py 2count = 0
python
1# test_part1.py 2import unittest 3import shared_module 4 5 6class SeparateProcessTestCase(unittest.TestCase): 7 8 def test_increament(self): 9 self.assertEqual(shared_module.count, 0) 10 shared_module.count += 1
python
1# test_part2.py 2# (test_part1.pyと同じ内容)
test_part1.py
とtest_part2.py
をまとめてtestする為に以下の三つのコマンドを試しましたが
python -m unittest discover -s ./tests
nosetests
nosetests --process-restartworker
三つとも全く同じ以下の出力で失敗しました。
text
1.F 2====================================================================== 3FAIL: test_increament (test_part2.SeparateProcessTestCase) 4---------------------------------------------------------------------- 5Traceback (most recent call last): 6 File "<省略>/test_part2.py", line 8, in test_increament 7 self.assertEqual(shared_module.count, 0) 8AssertionError: 1 != 0 9 10---------------------------------------------------------------------- 11Ran 2 tests in 0.006s 12 13FAILED (failures=1)
なのでtest_part1.py
とtest_part2.py
は同一のプロセスでtestされているようです。独立したプロセスで実行させるにはどうすれば良いでしょうか?
追記
stackoverflowにこのような回答があるところを見ると、unittestやnoseではファイルごとに独立したプロセスは与えられないようです。
あなたの回答
tips
プレビュー