我有以下类文件和相应的测试文件。
但是当我运行时
dir.py:
import os
class Dir:
def __init__(self, path=''):
self.path = path
@property
def path(self):
return self._path
@path.setter
def path(self, path):
abspath = os.path.abspath(path)
if abspath.exists():
self._path = path
else:
raise IOError(f'{path} does not exist')
和 dir_test.py:
import unittest
from ..dir import Dir
class TestDir(unittest.TestCase):
def IOErrorIfPathNotExists(self):
with self.assertRaises(IOError):
Dir.path = "~/invalidpath/"
with self.assertRaises(IOError):
Dir('~/invalidpath/')
if __name__ == "__main__":
unittest.main()
但是当我运行时
pytest -x dir_test.py
它只是打印出no tests ran in 0.01 seconds
,我不知道为什么。这是我第一次使用pytest,除了从exercism.io的练习中使用外,我看不出与他们的测试文件有任何区别。
我在虚拟环境(Python 3.6.5)中运行它,通过pip
安装了pytest
和pytest-cache
。