Skip to content

Commit 6332620

Browse files
committed
rewrite pytest-mypy-plugin extension code to use new hook
1 parent df021f6 commit 6332620

File tree

6 files changed

+32
-73
lines changed

6 files changed

+32
-73
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ jobs:
88
python: 3.7
99
script: |
1010
set -e
11-
pip install pytest_plugin/
12-
pytest -p no:pytest-mypy-plugins
11+
pytest
1312
1413
- name: Typecheck Django test suite
1514
python: 3.7

pytest.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
testpaths = ./test-data
33
addopts =
44
--tb=native
5-
--mypy-ini-file=./test-data/plugins.ini
65
-s
76
-v
8-
--cache-clear
7+
--cache-clear
8+
--mypy-ini-file=./test-data/plugins.ini
9+
--mypy-extension-hook=scripts.tests_extension_hook.django_plugin_hook

pytest_plugin/collect.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

pytest_plugin/setup.py

Lines changed: 0 additions & 27 deletions
This file was deleted.
File renamed without changes.

scripts/tests_extension_hook.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from pytest_mypy.collect import File
2+
from pytest_mypy.item import YamlTestItem
3+
4+
5+
def django_plugin_hook(test_item: YamlTestItem) -> None:
6+
settings = {
7+
'SECRET_KEY': '"1"',
8+
}
9+
additional_settings = test_item.parsed_test_data.get('additional_settings')
10+
if additional_settings:
11+
for item in additional_settings:
12+
name, _, val = item.partition('=')
13+
settings[name] = val
14+
15+
installed_apps = test_item.parsed_test_data.get('installed_apps', None)
16+
if installed_apps is not None:
17+
installed_apps += ['django.contrib.contenttypes']
18+
installed_apps_as_str = '(' + ','.join([repr(app) for app in installed_apps]) + ',)'
19+
20+
pyproject_toml_file = File(path='pyproject.toml',
21+
content='[tool.django-stubs]\ndjango_settings_module=\'mysettings\'')
22+
test_item.files.append(pyproject_toml_file)
23+
24+
settings_contents = f'INSTALLED_APPS={installed_apps_as_str}\n'
25+
settings_contents += '\n'.join([f'{key}={val}' for key, val in settings.items()])
26+
27+
mysettings_file = File(path='mysettings.py', content=settings_contents)
28+
test_item.files.append(mysettings_file)

0 commit comments

Comments
 (0)