Skip to content

Commit e050554

Browse files
committed
mypy config to exclude, and test selection via markers
- mypy was configred via `files` which fails when specifying a target dir. Now turned into an exclude in the config, and adding explicit files to the Makefile when a service is selected. - added SKIP_MYPY to be able to skip mypy check (as long as the mypy chnage is not complete) - using conftest.py to give all the tests default markers - the include/exclude from the makefile is now in the conftest.py marking as well - for services, also picking up test that reference that service in its name (specific pattern)
1 parent 200b6b3 commit e050554

File tree

3 files changed

+298
-17
lines changed

3 files changed

+298
-17
lines changed

Makefile

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
SHELL := /bin/bash
22

33
ifdef SERVICE_NAME
4-
TEST_SERVICE = test_${SERVICE_NAME}
4+
TEST_SERVICE = and ${SERVICE_NAME}
5+
TEST_SERVICE_DIR = test_${SERVICE_NAME}
56
TF_SERVICE_NAME = ${SERVICE_NAME}
7+
MYPY_EXPLICIT_FILES ?= moto/${SERVICE_NAME}/*.py*
68
endif
79

8-
TF_SERVICE_NAME ?= "default"
10+
TF_SERVICE_NAME ?= default
911
TEST_NAMES ?= "*"
1012

13+
# Parallel tests will be run separate
14+
# -m tags are specified in tests/conftest.py, or on individual files/tests
1115
ifeq ($(TEST_SERVER_MODE), true)
12-
# exclude test_kinesisvideoarchivedmedia
13-
# because testing with moto_server is difficult with data-endpoint
14-
TEST_EXCLUDE := --ignore tests/test_kinesisvideoarchivedmedia --ignore tests/test_acm --ignore tests/test_amp --ignore tests/test_awslambda --ignore tests/test_batch --ignore tests/test_ec2 --ignore tests/test_sqs
15-
# Parallel tests will be run separate
16-
PARALLEL_TESTS := ./tests/test_acm/ ./tests/test_acmpca/ ./tests/test_amp/ ./tests/test_awslambda ./tests/test_batch ./tests/test_ec2 ./tests/test_sqs
16+
TEST_EXCLUDE := -m "not parallel and not parallel_server_only and not skip_server ${TEST_SERVICE}"
17+
PARALLEL_TESTS := -m "parallel or parallel_server_only ${TEST_SERVICE}"
1718
else
18-
TEST_EXCLUDE := --ignore tests/test_batch --ignore tests/test_ec2 --ignore tests/test_sqs
19-
PARALLEL_TESTS := ./tests/test_batch ./tests/test_ec2 ./tests/test_sqs
19+
TEST_EXCLUDE := -m "not parallel ${TEST_SERVICE}"
20+
PARALLEL_TESTS := -m "parallel ${TEST_SERVICE}"
2021
endif
2122

2223
init:
@@ -25,29 +26,30 @@ init:
2526

2627
lint:
2728
@echo "Running flake8..."
28-
flake8 moto/${SERVICE_NAME} tests/${TEST_SERVICE}
29+
flake8 moto/${SERVICE_NAME} tests/${TEST_SERVICE_DIR}
2930
@echo "Running black... "
3031
$(eval black_version := $(shell grep "^black==" requirements-dev.txt | sed "s/black==//"))
3132
@echo "(Make sure you have black-$(black_version) installed, as other versions will produce different results)"
32-
black --check moto/${SERVICE_NAME} tests/${TEST_SERVICE}
33+
black --check moto/${SERVICE_NAME} tests/${TEST_SERVICE_DIR}
3334
@echo "Running pylint..."
34-
pylint -j 0 moto/${SERVICE_NAME} tests/${TEST_SERVICE}
35+
pylint -j 0 moto/${SERVICE_NAME} tests/${TEST_SERVICE_DIR}
3536
@echo "Running MyPy..."
36-
mypy --install-types --non-interactive moto/${SERVICE_NAME}
37+
if [[ "${SKIP_MYPY}" == "" ]]; then mypy --install-types --non-interactive ${MYPY_EXPLICIT_FILES}; else echo "Skipping"; fi
3738

3839
format:
3940
black moto/ tests/
4041

4142
test-only:
4243
rm -f .coverage
4344
rm -rf cover
44-
pytest -sv --cov=moto --cov-report xml ./tests/${TEST_SERVICE} $(TEST_EXCLUDE)
45+
pytest -sv --cov=moto --cov-report xml ./tests $(TEST_EXCLUDE) ${PYTEST_ARGS}
4546
# https://github.com/aws/aws-xray-sdk-python/issues/196 - Run these tests separately without Coverage enabled
46-
if [[ "${SERVICE_NAME}" == "" || "${SERVICE_NAME}" == "xray" ]]; then pytest -sv ./tests/test_xray; else echo "Skipping"; fi
47-
if [[ "$(filter %${SERVICE_NAME},$(PARALLEL_TESTS))" != "" ]]; then MOTO_CALL_RESET_API=false pytest --cov=moto --cov-report xml --cov-append -n 4 $(filter %${SERVICE_NAME},$(PARALLEL_TESTS)); else echo "Skipping"; fi
47+
if [[ "${SERVICE_NAME}" == "" || "${SERVICE_NAME}" == "xray" ]]; then pytest -sv ./tests/test_xray ${PYTEST_ARGS}; else echo "Skipping"; fi
48+
MOTO_CALL_RESET_API=false pytest --cov=moto --cov-report xml --cov-append -n 4 $(PARALLEL_TESTS) ${PYTEST_ARGS}
4849

4950
test: lint test-only
50-
@echo "USAGE: make test [SERVICE_NAME=s3] (defaults to all)"
51+
@echo "USAGE: make test [SERVICE_NAME=s3] [SKIP_MYPY=true]"
52+
@echo " defaults to all services and running mypy (not all services are mypy proof, see also setup.cfg)"
5153

5254
terraformtests:
5355
@echo "Make sure that the MotoServer is already running on port 4566 (moto_server -p 4566)"

setup.cfg

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,130 @@ universal=1
211211

212212
[tool:pytest]
213213
markers =
214+
# special cases
214215
network: marks tests which require network connection
216+
parallel: can be run in parallel
217+
parallel_server_only: can be run in parallel (in server mode only)
218+
skip_server: should not be run in server mode
219+
# services
220+
acm: acm service
221+
acmpca: acmpca service
222+
amp: amp service
223+
apigateway: apigateway service
224+
apigatewayv2: apigatewayv2 service
225+
applicationautoscaling: applicationautoscaling service
226+
appsync: appsync service
227+
athena: athena service
228+
autoscaling: autoscaling service
229+
awslambda: awslambda service
230+
batch: batch service
231+
batch_simple: batch_simple service
232+
budgets: budgets service
233+
ce: ce service
234+
cloudformation: cloudformation service
235+
cloudfront: cloudfront service
236+
cloudtrail: cloudtrail service
237+
cloudwatch: cloudwatch service
238+
codebuild: codebuild service
239+
codecommit: codecommit service
240+
codepipeline: codepipeline service
241+
cognitoidentity: cognitoidentity service
242+
cognitoidp: cognitoidp service
243+
comprehend: comprehend service
244+
config: config service
245+
databrew: databrew service
246+
datapipeline: datapipeline service
247+
datasync: datasync service
248+
dax: dax service
249+
dms: dms service
250+
ds: ds service
251+
dynamodb: dynamodb service
252+
dynamodb_v20111205: dynamodb_v20111205 service
253+
dynamodbstreams: dynamodbstreams service
254+
ebs: ebs service
255+
ec2: ec2 service
256+
ec2instanceconnect: ec2instanceconnect service
257+
ecr: ecr service
258+
ecs: ecs service
259+
efs: efs service
260+
eks: eks service
261+
elasticache: elasticache service
262+
elasticbeanstalk: elasticbeanstalk service
263+
elastictranscoder: elastictranscoder service
264+
elb: elb service
265+
elbv2: elbv2 service
266+
emr: emr service
267+
emrcontainers: emrcontainers service
268+
emrserverless: emrserverless service
269+
es: es service
270+
events: events service
271+
firehose: firehose service
272+
forecast: forecast service
273+
glacier: glacier service
274+
glue: glue service
275+
greengrass: greengrass service
276+
guardduty: guardduty service
277+
iam: iam service
278+
identitystore: identitystore service
279+
instance_metadata: instance_metadata service
280+
iot: iot service
281+
iotdata: iotdata service
282+
kinesis: kinesis service
283+
kinesisvideo: kinesisvideo service
284+
kinesisvideoarchivedmedia: kinesisvideoarchivedmedia service
285+
kms: kms service
286+
logs: logs service
287+
managedblockchain: managedblockchain service
288+
mediaconnect: mediaconnect service
289+
medialive: medialive service
290+
mediapackage: mediapackage service
291+
mediastore: mediastore service
292+
mediastoredata: mediastoredata service
293+
meteringmarketplace: meteringmarketplace service
294+
moto_api: moto_api service
295+
moto_server: moto_server service
296+
mq: mq service
297+
neptune: neptune service
298+
opsworks: opsworks service
299+
organizations: organizations service
300+
packages: packages service
301+
personalize: personalize service
302+
pinpoint: pinpoint service
303+
polly: polly service
304+
quicksight: quicksight service
305+
ram: ram service
306+
rds: rds service
307+
redshift: redshift service
308+
redshiftdata: redshiftdata service
309+
rekognition: rekognition service
310+
resourcegroups: resourcegroups service
311+
resourcegroupstaggingapi: resourcegroupstaggingapi service
312+
route53: route53 service
313+
route53resolver: route53resolver service
314+
s3: s3 service
315+
s3bucket_path: s3bucket_path service
316+
s3control: s3control service
317+
sagemaker: sagemaker service
318+
sdb: sdb service
319+
secretsmanager: secretsmanager service
320+
servicediscovery: servicediscovery service
321+
servicequotas: servicequotas service
322+
ses: ses service
323+
signer: signer service
324+
sns: sns service
325+
sqs: sqs service
326+
ssm: ssm service
327+
ssoadmin: ssoadmin service
328+
stepfunctions: stepfunctions service
329+
sts: sts service
330+
support: support service
331+
swf: swf service
332+
textract: textract service
333+
timestreamwrite: timestreamwrite service
334+
transcribe: transcribe service
335+
utilities: utilities service
336+
wafv2: wafv2 service
337+
xray: xray service
215338

216339
[coverage:run]
217340
relative_files = True
@@ -230,6 +353,13 @@ enable = anomalous-backslash-in-string, arguments-renamed, dangerous-default-val
230353

231354
[mypy]
232355
files= moto/a*,moto/b*,moto/c*,moto/d*,moto/e*,moto/moto_api,moto/neptune
356+
exclude = (?x)(
357+
^moto/[f-l]
358+
| ^moto/m(?!oto_api) # all m*, except moto_apip
359+
| ^moto/n(?!eptune) # all n*, except neptune
360+
| ^moto/[o-z]
361+
)
362+
233363
show_column_numbers=True
234364
show_error_codes = True
235365
disable_error_code=abstract

tests/conftest.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import pytest
2+
3+
SERVICES = (
4+
"acm",
5+
"acmpca",
6+
"amp",
7+
"apigateway",
8+
"apigatewayv2",
9+
"applicationautoscaling",
10+
"appsync",
11+
"athena",
12+
"autoscaling",
13+
"awslambda",
14+
"batch",
15+
"batch_simple",
16+
"budgets",
17+
"ce",
18+
"cloudformation",
19+
"cloudfront",
20+
"cloudtrail",
21+
"cloudwatch",
22+
"codebuild",
23+
"codecommit",
24+
"codepipeline",
25+
"cognitoidentity",
26+
"cognitoidp",
27+
"comprehend",
28+
"config",
29+
"databrew",
30+
"datapipeline",
31+
"datasync",
32+
"dax",
33+
"dms",
34+
"ds",
35+
"dynamodb",
36+
"dynamodb_v20111205",
37+
"dynamodbstreams",
38+
"ebs",
39+
"ec2",
40+
"ec2instanceconnect",
41+
"ecr",
42+
"ecs",
43+
"efs",
44+
"eks",
45+
"elasticache",
46+
"elasticbeanstalk",
47+
"elastictranscoder",
48+
"elb",
49+
"elbv2",
50+
"emr",
51+
"emrcontainers",
52+
"emrserverless",
53+
"es",
54+
"events",
55+
"firehose",
56+
"forecast",
57+
"glacier",
58+
"glue",
59+
"greengrass",
60+
"guardduty",
61+
"iam",
62+
"identitystore",
63+
"instance_metadata",
64+
"iot",
65+
"iotdata",
66+
"kinesis",
67+
"kinesisvideo",
68+
"kinesisvideoarchivedmedia",
69+
"kms",
70+
"logs",
71+
"managedblockchain",
72+
"mediaconnect",
73+
"medialive",
74+
"mediapackage",
75+
"mediastore",
76+
"mediastoredata",
77+
"meteringmarketplace",
78+
"moto_api",
79+
"moto_server",
80+
"mq",
81+
"neptune",
82+
"opsworks",
83+
"organizations",
84+
"packages",
85+
"personalize",
86+
"pinpoint",
87+
"polly",
88+
"quicksight",
89+
"ram",
90+
"rds",
91+
"redshift",
92+
"redshiftdata",
93+
"rekognition",
94+
"resourcegroups",
95+
"resourcegroupstaggingapi",
96+
"route53",
97+
"route53resolver",
98+
"s3",
99+
"s3bucket_path",
100+
"s3control",
101+
"sagemaker",
102+
"sdb",
103+
"secretsmanager",
104+
"servicediscovery",
105+
"servicequotas",
106+
"ses",
107+
"signer",
108+
"sns",
109+
"sqs",
110+
"ssm",
111+
"ssoadmin",
112+
"stepfunctions",
113+
"sts",
114+
"support",
115+
"swf",
116+
"textract",
117+
"timestreamwrite",
118+
"transcribe",
119+
"utilities",
120+
"wafv2",
121+
"xray",
122+
)
123+
124+
125+
EXTRA_MARKERS_TEST_DIRS = {
126+
"acm": (pytest.mark.parallel_server_only,),
127+
"acmpca": (pytest.mark.parallel_server_only,),
128+
"amp": (pytest.mark.parallel_server_only,),
129+
"awslambda": (pytest.mark.parallel_server_only,),
130+
"batch": (pytest.mark.parallel,),
131+
"ec2": (pytest.mark.parallel,),
132+
# exclude test_kinesisvideoarchivedmedia
133+
# because testing with moto_server is difficult with data-endpoint
134+
"kinesisvideoarchivedmedia": (pytest.mark.skip_server,),
135+
"sqs": (pytest.mark.parallel,),
136+
}
137+
138+
139+
def pytest_collection_modifyitems(items): # noqa: SC200
140+
for item in items:
141+
for service, markers in EXTRA_MARKERS_TEST_DIRS.items():
142+
if f"tests/test_{service}/" in item.nodeid: # noqa: SC200
143+
for marker in markers:
144+
item.add_marker(marker)
145+
for service in SERVICES:
146+
if f"tests/test_{service}/" in item.nodeid: # noqa: SC200
147+
item.add_marker(getattr(pytest.mark, service))
148+
if f"_{service}.py" in item.nodeid:
149+
item.add_marker(getattr(pytest.mark, service))

0 commit comments

Comments
 (0)