Skip to content

Commit e1de864

Browse files
Run tests in parallel (#2580)
Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent a3f2a55 commit e1de864

File tree

8 files changed

+8
-10
lines changed

8 files changed

+8
-10
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
6969
# Must match `shard` definition in the test matrix:
7070
- name: Run pytest tests
71-
run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} tests
71+
run: PYTHONPATH='.' pytest --num-shards=4 --shard-id=${{ matrix.shard }} -n auto tests
7272
- name: Run mypy on the test cases
7373
run: mypy --strict tests/assert_type
7474

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ You can also run pre-commit per file or for a specific path, simply replace "--a
6868
To execute the unit tests, simply run:
6969

7070
```bash
71-
pytest
71+
pytest -n auto
7272
```
7373

7474
If you get some unexpected results or want to be sure that tests run is not affected by previous one, remove `mypy` cache:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pre-commit==4.2.0
33
pytest==8.3.5
44
pytest-mypy-plugins==3.2.0
55
pytest-shard==0.1.2
6+
pytest-xdist==3.6.1
67

78
# Django deps:
89
psycopg2-binary

scripts/tests_extension_hook.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ def django_plugin_hook(test_item: YamlTestItem) -> None:
3232

3333
mysettings_file = File(path="mysettings.py", content=custom_settings)
3434
test_item.files.append(mysettings_file)
35+
36+
if hasattr(test_item.config, "workerinput"):
37+
# Append worker ID to cache directory to prevent race conditions during parallel mypy testing
38+
# Avoids potential file corruption when multiple processes access/write cached files simultaneously
39+
test_item.incremental_cache_dir += test_item.config.workerinput["workerid"]

tests/typecheck/fields/test_base.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
some_decimal = models.DecimalField(max_digits=10, decimal_places=5)
4545
4646
- case: test_add_id_field_if_no_primary_key_defined
47-
disable_cache: true
4847
main: |
4948
from myapp.models import User
5049
reveal_type(User().id) # N: Revealed type is "builtins.int"
@@ -59,7 +58,6 @@
5958
pass
6059
6160
- case: test_do_not_add_id_if_field_with_primary_key_True_defined
62-
disable_cache: true
6361
main: |
6462
from myapp.models import User
6563
reveal_type(User().my_pk) # N: Revealed type is "builtins.int"

tests/typecheck/managers/querysets/test_from_queryset.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@
453453
NewManager = models.Manager.from_queryset(ModelQuerySet)
454454
455455
- case: from_queryset_with_inherited_manager_and_typing_no_return
456-
disable_cache: true
457456
main: |
458457
from myapp.models import MyModel
459458
reveal_type(MyModel().objects) # N: Revealed type is "myapp.managers.ManagerFromModelQuerySet[myapp.models.MyModel]"
@@ -684,7 +683,6 @@
684683
# For details see: https://github.com/typeddjango/django-stubs/issues/1022
685684
- case: from_queryset_custom_auth_user_model
686685
# Cache needs to be disabled to consistently reproduce the bug
687-
disable_cache: true
688686
main: |
689687
from users.models import User
690688
custom_settings: |

tests/typecheck/models/test_extra_methods.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
gender = models.CharField(max_length=100, choices=GENDER_CHOICES)
2121
2222
- case: date_datetime_fields_have_get_next_by_get_previous_by
23-
disable_cache: true
2423
parametrized:
2524
- allow_any: "true"
2625
- allow_any: "false"

tests/typecheck/test_settings.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
- case: settings_loaded_from_different_files
2-
disable_cache: true
32
main: |
43
from django.conf import settings
54
# standard settings
@@ -61,7 +60,6 @@
6160
6261
6362
- case: settings_loaded_from_runtime_magic
64-
disable_cache: true
6563
main: |
6664
from django.conf import settings
6765
@@ -81,7 +79,6 @@
8179
8280
8381
- case: settings_loaded_from_runtime_magic_strict_default
84-
disable_cache: true
8582
main: |
8683
from django.conf import settings
8784

0 commit comments

Comments
 (0)