forked from facebookresearch/ParlAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
58 lines (48 loc) · 1.83 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
This is used to configure markers on tests based on filename.
We use this to split up tests into different circleci runs.
"""
import os
import pathlib
import random
import pytest
# TODO: rename the folders nicer so they make more sense, maybe even have
# a 1:1 correspondance with the circleci name
def pytest_collection_modifyitems(config, items):
# handle circleci parallelism
if 'CIRCLE_NODE_TOTAL' in os.environ:
total = int(os.environ['CIRCLE_NODE_TOTAL'])
index = int(os.environ['CIRCLE_NODE_INDEX'])
else:
total = 1
index = 0
# python 3.4/3.5 compat: rootdir = pathlib.Path(str(config.rootdir))
rootdir = pathlib.Path(config.rootdir)
parallels = [i % total == index for i in range(len(items))]
random.Random(42).shuffle(parallels)
deselected = []
for parallel, item in zip(parallels, items):
rel_path = str(pathlib.Path(item.fspath).relative_to(rootdir))
if not parallel:
deselected.append(item)
elif "nightly/gpu/" in rel_path:
item.add_marker("nightly_gpu")
elif "nightly/cpu/" in rel_path:
item.add_marker("nightly_cpu")
elif "datatests/" in rel_path:
item.add_marker("data")
elif "tasks/" in rel_path:
item.add_marker("tasks")
elif "parlai/mturk/core/test/" in rel_path:
item.add_marker("mturk")
elif "/" not in rel_path[6:]:
item.add_marker("unit")
else:
raise ValueError(f"Couldn't categorize '{rel_path}'")
config.hook.pytest_deselected(items=deselected)
for d in deselected:
items.remove(d)