-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AlexeySanko
committed
Oct 15, 2017
1 parent
d0f8f80
commit 8dae883
Showing
9 changed files
with
378 additions
and
39 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/integrationtest/python/should_correctly_pass_failure_pytest_plugin_tests.py
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,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of PyBuilder | ||
# | ||
# Copyright 2011-2015 PyBuilder Team | ||
# | ||
# Licensed 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. | ||
|
||
from os import sep as os_sep | ||
import unittest | ||
|
||
from integrationtest_support import IntegrationTestSupport | ||
from pybuilder.errors import BuildFailedException | ||
|
||
|
||
failure_pytest_test_content = """ | ||
def test_pytest_base_failure(): | ||
assert False | ||
""" | ||
|
||
|
||
class TestDefaultParamFailure(IntegrationTestSupport): | ||
def test_pytest(self): | ||
self.write_build_file(""" | ||
from pybuilder.core import use_plugin, init | ||
use_plugin("python.pytest") | ||
@init | ||
def init (project): | ||
pass | ||
""") | ||
|
||
unittest_path = "src/unittest/python" | ||
unittest_file = unittest_path + os_sep + "failure_test.py" | ||
report_file = "target/reports/junit.xml" | ||
|
||
self.create_directory(unittest_path) | ||
self.write_file(unittest_file, failure_pytest_test_content) | ||
|
||
reactor = self.prepare_reactor() | ||
self.assertRaises(BuildFailedException, reactor.build, "run_unit_tests") | ||
|
||
self.assert_file_exists(unittest_file) | ||
self.assert_file_exists(report_file) | ||
|
||
self.assert_file_contains(report_file, 'tests="1"') | ||
self.assert_file_contains(report_file, 'errors="0"') | ||
self.assert_file_contains(report_file, 'failures="1"') | ||
self.assert_file_contains(report_file, 'skips="0"') | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
69 changes: 69 additions & 0 deletions
69
src/integrationtest/python/should_run_pytest_plugin_tests.py
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,69 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of PyBuilder | ||
# | ||
# Copyright 2011-2015 PyBuilder Team | ||
# | ||
# Licensed 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. | ||
|
||
from os import sep as os_sep | ||
import unittest | ||
|
||
from integrationtest_support import IntegrationTestSupport | ||
|
||
|
||
success_pytest_test_content = """ | ||
def test_pytest_base_success(): | ||
assert True | ||
def test_pytest_base_skip(): | ||
assert True | ||
""" | ||
|
||
|
||
class TestCustomParamSuccess(IntegrationTestSupport): | ||
def test_pytest(self): | ||
self.write_build_file(""" | ||
from pybuilder.core import use_plugin, init | ||
use_plugin("python.pytest") | ||
@init | ||
def init (project): | ||
project.set_property("dir_source_pytest_python", "some_dir/unittest") | ||
project.set_property("pytest_report_file", "some_dir/junit.xml") | ||
project.get_property("pytest_extra_args").append("-k") | ||
project.get_property("pytest_extra_args").append("test_pytest_base_success") | ||
""") | ||
|
||
unittest_path = "some_dir/unittest" | ||
unittest_file = unittest_path + os_sep + "success_test.py" | ||
report_file = "some_dir/junit.xml" | ||
|
||
self.create_directory(unittest_path) | ||
self.write_file(unittest_file, success_pytest_test_content) | ||
|
||
reactor = self.prepare_reactor() | ||
reactor.build("run_unit_tests") | ||
|
||
self.assert_file_exists(unittest_file) | ||
self.assert_file_exists(report_file) | ||
|
||
self.assert_file_contains(report_file, 'tests="1"') | ||
self.assert_file_contains(report_file, 'errors="0"') | ||
self.assert_file_contains(report_file, 'failures="0"') | ||
self.assert_file_contains(report_file, 'skips="0"') | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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,70 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2016 Alexey Sanko | ||
# | ||
# Licensed 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. | ||
|
||
from sys import path as sys_path | ||
|
||
from pybuilder.core import task, init, use_plugin, after | ||
from pybuilder.errors import MissingPrerequisiteException, BuildFailedException | ||
from pybuilder.utils import register_test_and_source_path_and_return_test_dir | ||
|
||
__author__ = 'Alexey Sanko' | ||
|
||
use_plugin("python.core") | ||
|
||
|
||
@init | ||
def initialize_pytest_plugin(project): | ||
""" Init default plugin project properties. """ | ||
project.plugin_depends_on('pytest') | ||
project.set_property_if_unset("dir_source_pytest_python", "src/unittest/python") | ||
project.set_property_if_unset("pytest_report_file", "target/reports/junit.xml") | ||
project.set_property_if_unset("pytest_extra_args", []) | ||
|
||
|
||
@after("prepare") | ||
def assert_pytest_available(logger): | ||
""" Asserts that the pytest module is available. """ | ||
logger.debug("Checking if pytest module is available.") | ||
|
||
try: | ||
import pytest | ||
logger.debug("Found pytest version %s" % pytest.__version__) | ||
except ImportError: | ||
raise MissingPrerequisiteException(prerequisite="pytest module", caller="plugin python.pytest") | ||
|
||
|
||
@task | ||
def run_unit_tests(project, logger): | ||
""" Call pytest for the sources of the given project. """ | ||
logger.info('pytest: Run unittests.') | ||
from pytest import main as pytest_main | ||
test_dir = register_test_and_source_path_and_return_test_dir(project, sys_path, 'pytest') | ||
extra_args = project.get_property("pytest_extra_args") | ||
try: | ||
pytest_args = [test_dir] | ||
if project.get_property('verbose'): | ||
pytest_args.append('-s') | ||
pytest_args.append('-v') | ||
pytest_args.append('--junit-xml') | ||
pytest_args.append(project.expand_path('$pytest_report_file')) | ||
pytest_args = pytest_args + (extra_args if extra_args else []) | ||
ret = pytest_main(pytest_args) | ||
if ret: | ||
raise BuildFailedException('pytest: unittests failed') | ||
else: | ||
logger.info('pytest: All unittests passed.') | ||
except: | ||
raise |
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.