forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BEAM-3713] Add pytest for unit tests (apache#9756)
This is apache#7949 without IT support. - Runs unit tests using pytest - tox: `tox -e py27-gcp-pytest,py36-pytest,etc.` - gradle: `../../gradlew pythonPreCommitPytest` - github PR phrase: `run python_pytest precommit` - Tests run in parallel (still single-threaded but on multiple worker processes). - no_xdist marker used for tests that don't work the xdist plugin. - Allows specifying test module in tox cmd line. Example: ```sh tox -e py27-pytest apache_beam.transforms.window_test ```
- Loading branch information
Showing
20 changed files
with
321 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
"""Pytest configuration and custom hooks.""" | ||
|
||
from __future__ import absolute_import | ||
|
||
import sys | ||
|
||
MAX_SUPPORTED_PYTHON_VERSION = (3, 8) | ||
|
||
# See pytest.ini for main collection rules. | ||
collect_ignore_glob = [] | ||
if sys.version_info < (3,): | ||
collect_ignore_glob.append('*_py3*.py') | ||
else: | ||
for minor in range(sys.version_info.minor + 1, | ||
MAX_SUPPORTED_PYTHON_VERSION[1] + 1): | ||
collect_ignore_glob.append('*_py3%d.py' % minor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
[pytest] | ||
junit_family = xunit2 | ||
|
||
# Disable class-name-based test discovery. | ||
python_classes = | ||
# Disable function-name-based test discovery. | ||
python_functions = | ||
# Discover tests using filenames. | ||
# See conftest.py for extra collection rules. | ||
python_files = test_*.py *_test.py *_test_py3*.py | ||
|
||
markers = | ||
# Tests using this marker conflict with the xdist plugin in some way, such | ||
# as enabling save_main_session. | ||
no_xdist: run without pytest-xdist plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Utility script for tox.ini for running unit tests. | ||
# | ||
# Runs tests in parallel, except those not compatible with xdist. Combines | ||
# exit statuses of runs, special-casing 5, which says that no tests were | ||
# selected. | ||
# | ||
# $1 - suite base name | ||
# $2 - additional arguments to pass to pytest | ||
|
||
envname=${1?First argument required: suite base name} | ||
posargs=$2 | ||
|
||
# Run with pytest-xdist and without. | ||
python setup.py pytest --addopts="-o junit_suite_name=${envname} \ | ||
--junitxml=pytest_${envname}.xml -m 'not no_xdist' -n 6 --pyargs ${posargs}" | ||
status1=$? | ||
python setup.py pytest --addopts="-o junit_suite_name=${envname}_no_xdist \ | ||
--junitxml=pytest_${envname}_no_xdist.xml -m 'no_xdist' --pyargs ${posargs}" | ||
status2=$? | ||
|
||
# Exit with error if no tests were run (status code 5). | ||
if [[ $status1 == 5 && $status2 == 5 ]]; then | ||
exit $status1 | ||
fi | ||
|
||
# Exit with error if one of the statuses has an error that's not 5. | ||
if [[ $status1 && $status1 != 5 ]]; then | ||
exit $status1 | ||
fi | ||
if [[ $status2 && $status2 != 5 ]]; then | ||
exit $status2 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.