File tree Expand file tree Collapse file tree 7 files changed +39
-0
lines changed Expand file tree Collapse file tree 7 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ py_pytest_test(
34
34
)
35
35
```
36
36
37
+ To use [ test sharding] ( https://bazel.build/reference/test-encyclopedia#test-sharding ) , also add ` requirement("pytest-shard") `
38
+ to ` deps ` .
39
+
37
40
## Disclaimer
38
41
39
42
I rely on this myself and will accept issue reports and contributions, however this only has a simple smoke test and isn't
Original file line number Diff line number Diff line change
1
+ # Enable after bazel 5.4.0 is removed from e2e tests to verify correct implementation of sharding.
2
+ # test --incompatible_check_sharding_support
Original file line number Diff line number Diff line change @@ -15,6 +15,17 @@ py_pytest_test(
15
15
],
16
16
)
17
17
18
+ py_pytest_test (
19
+ name = "test_sharded" ,
20
+ size = "small" ,
21
+ srcs = ["test_sharded.py" ],
22
+ shard_count = 2 ,
23
+ deps = [
24
+ requirement ("pytest" ),
25
+ requirement ("pytest-shard" ),
26
+ ],
27
+ )
28
+
18
29
build_test (
19
30
name = "smoke_test" ,
20
31
targets = [
Original file line number Diff line number Diff line change 1
1
pytest==7.3.2
2
+ pytest-shard==0.1.2
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ pluggy==1.2.0 \
23
23
pytest == 7.3.2 \
24
24
--hash =sha256:cdcbd012c9312258922f8cd3f1b62a6580fdced17db6014896053d47cddf9295 \
25
25
--hash =sha256:ee990a3cc55ba808b80795a79944756f315c67c12b56abd3ac993a7b8c17030b
26
+ # via
27
+ # -r requirements.in
28
+ # pytest-shard
29
+ pytest-shard == 0.1.2 \
30
+ --hash =sha256:407a1df385cebe1feb9b4d2e7eeee8b044f8a24f0919421233159a17c59be2b9 \
31
+ --hash =sha256:b86a967fbfd1c8e50295095ccda031b7e890862ee06531d5142844f4c1d1cd67
26
32
# via -r requirements.in
27
33
tomli == 2.0.1 \
28
34
--hash =sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+
4
+ def test_shard_0 ():
5
+ assert os .environ ["TEST_SHARD_INDEX" ] == "0"
6
+
7
+
8
+ def test_shard_1 ():
9
+ assert os .environ ["TEST_SHARD_INDEX" ] == "1"
Original file line number Diff line number Diff line change 16
16
if os .environ .get ("XML_OUTPUT_FILE" ):
17
17
pytest_args .append ("--junitxml={xml_output_file}" .format (xml_output_file = os .environ .get ("XML_OUTPUT_FILE" )))
18
18
19
+ # Handle test sharding - requires pytest-shard plugin.
20
+ if os .environ .get ("TEST_SHARD_INDEX" ) and os .environ .get ("TEST_TOTAL_SHARDS" ):
21
+ pytest_args .append ("--shard-id={shard_id}" .format (shard_id = os .environ .get ("TEST_SHARD_INDEX" )))
22
+ pytest_args .append ("--num-shards={num_shards}" .format (num_shards = os .environ .get ("TEST_TOTAL_SHARDS" )))
23
+ if os .environ .get ("TEST_SHARD_STATUS_FILE" ):
24
+ open (os .environ ["TEST_SHARD_STATUS_FILE" ], "a" ).close ()
25
+
19
26
# Handle plugins that generate reports - if they are provided with relative paths (via args),
20
27
# re-write it under bazel's test undeclared outputs dir.
21
28
if os .environ .get ("TEST_UNDECLARED_OUTPUTS_DIR" ):
You can’t perform that action at this time.
0 commit comments