Skip to content

Commit a0576bb

Browse files
authored
Add pytest (#127)
* Add pytest * Fix use pytest instead of python setup.py test * Fix add pytest section * Fix tox.ini * Fix tests not working after pyproject.toml was introduced * Fix requirements.txt format
1 parent 1d5b6ce commit a0576bb

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
3333
- name: Test
3434
run: |
35-
python setup.py test
35+
pytest
3636
3737
- name: Flake8
3838
run: |

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ include = ["doq"]
4747

4848
[tool.setuptools_scm]
4949
write_to = "doq/_version.py"
50+
51+
[tool.pytest.ini_options]
52+
addopts = "-ra"
53+
testpaths = ["tests"]

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ jinja2==3.1.2
1212
pep8-naming==0.13.3
1313
parameterized==0.9.0
1414
parso==0.8.3
15+
pytest==7.4.0
1516
toml==0.10.2

tests/test_config.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ def setUpClass(cls):
2222
def test_find_setupcfg(self):
2323
rootpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
2424
expected = os.path.join(rootpath, 'setup.cfg')
25+
paths = []
2526
for path in find_config_path():
26-
self.assertEqual(expected, path)
27+
paths.append(path)
28+
self.assertIn(expected, paths)
2729

2830
def test_read_setupcfg(self):
2931
setupcfg = os.path.join(self.fixtures_path, 'setup.cfg')
@@ -87,6 +89,12 @@ def test_find_config(self):
8789
)
8890

8991
def test_find_config_not_found(self):
92+
pyproject_path = os.path.join(self.basepath, 'pyproject.toml')
93+
shutil.move(
94+
pyproject_path,
95+
os.path.join(self.basepath, '_pyproject.toml'),
96+
)
97+
9098
args = argparse.Namespace(
9199
start=1,
92100
end=0,
@@ -104,6 +112,10 @@ def test_find_config_not_found(self):
104112
)
105113
configs = find_config(args)
106114
self.assertDictEqual({}, configs)
115+
shutil.move(
116+
os.path.join(self.basepath, '_pyproject.toml'),
117+
pyproject_path,
118+
)
107119

108120

109121
class ConfigPyprojectTomlTestCase(TestCase):
@@ -114,18 +126,13 @@ def setUpClass(cls):
114126

115127
def test_find_pyproject_toml(self):
116128
rootpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
117-
fixtures_path = os.path.join(self.fixtures_path, 'pyproject.toml')
118-
shutil.copyfile(fixtures_path, os.path.join(rootpath, 'pyproject.toml'))
119-
120129
expected = [
121130
os.path.join(rootpath, 'setup.cfg'),
122131
os.path.join(rootpath, 'pyproject.toml'),
123132
]
124133
for path in find_config_path():
125134
self.assertIn(path, expected)
126135

127-
os.remove(os.path.join(rootpath, 'pyproject.toml'))
128-
129136
def test_read_pyproject_toml(self):
130137
pyproject = os.path.join(self.fixtures_path, 'pyproject.toml')
131138
defaults = read_pyproject_toml(pyproject)

tox.ini

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[tox]
2-
envlist = py36,py37,py38,py39,py310,flake8
2+
envlist = py310,py311,flake8
33

44
[testenv]
5-
commands=python setup.py test
5+
commands=pytest
66
deps=
77
parso
88
jinja2
99
parameterized
1010
toml
11+
pytest
1112

1213
[testenv:flake8]
1314
deps = flake8
14-
commands = flake8 doq tests setup.py
15+
commands = flake8 doq tests

0 commit comments

Comments
 (0)