├── DependencyLibrary.py ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst └── setup.py /DependencyLibrary.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: 0BSD 2 | # Copyright 2017 Alexander Kozhevnikov 3 | 4 | from sys import modules as _modules 5 | 6 | from robot.api import logger as _logger 7 | from robot.api import SkipExecution as _SkipExecution 8 | 9 | 10 | __all__ = ('depends_on_test', 'depends_on_suite') 11 | __version__ = '4.0.1' 12 | 13 | 14 | ROBOT_LISTENER_API_VERSION = 3 15 | ROBOT_LIBRARY_LISTENER = _modules[__name__] 16 | 17 | 18 | _test_status_map = {} 19 | _suite_status_map = {} 20 | 21 | 22 | def start_test(test, result): 23 | _test_status_map[test.name.lower()] = Ellipsis 24 | 25 | 26 | def end_test(test, result): 27 | _test_status_map[test.name.lower()] = result.status 28 | 29 | 30 | def start_suite(suite, result): 31 | _suite_status_map[suite.name.lower()] = Ellipsis 32 | 33 | 34 | def end_suite(suite, result): 35 | _suite_status_map[suite.name.lower()] = result.status 36 | 37 | 38 | def _depends_on(status_map, dependency_type, name): 39 | message = 'Dependency not met: ' + dependency_type + ' ' + repr(name) 40 | status = status_map.get(name.lower(), None) 41 | if status is None: 42 | _logger.warn(message + ' not found.') 43 | return 44 | if status is Ellipsis: 45 | _logger.warn(message + ' mid-execution.') 46 | return 47 | if status == 'PASS': 48 | return 49 | if status == 'SKIP': 50 | raise _SkipExecution(message + ' was skipped.') 51 | assert status == 'FAIL', message + ' has status ' + repr(status) + '.' 52 | raise _SkipExecution(message + ' failed.') 53 | 54 | 55 | def depends_on_test(name): 56 | _depends_on(_test_status_map, 'test case', name) 57 | 58 | 59 | def depends_on_suite(name, status='PASS'): 60 | _depends_on(_suite_status_map, 'test suite', name) 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Alexander Kozhevnikov 2 | 3 | Permission to use, copy, modify, and distribute this software for any 4 | purpose with or without fee is hereby granted. 5 | 6 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 7 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 8 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 9 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 10 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 11 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 12 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 13 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | python3 setup.py sdist bdist_wheel --universal 3 | 4 | clean: 5 | rm -rf __pycache__ build *.egg-info dist 6 | rm -f *.py[oc] MANIFEST *.html *.xml 7 | 8 | test: 9 | PYTHONPATH=. robot README.rst 10 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Robot Framework Dependency Library 2 | ================================== 3 | 4 | Declare dependencies between tests. 5 | 6 | Ideally tests are independent, but when tests depend 7 | on earlier tests, DependencyLibrary makes it easy to 8 | explicitly declare these dependencies and have tests 9 | that depend on each other do the right thing. 10 | 11 | 12 | Versioning 13 | ---------- 14 | 15 | This library's version numbers follow the `SemVer 2.0.0 16 | specification `_. 17 | 18 | 19 | Installation 20 | ------------ 21 | 22 | :: 23 | 24 | pip install robotframework-dependencylibrary 25 | 26 | 27 | Usage 28 | ----- 29 | 30 | First, include the library in your tests: 31 | 32 | .. code:: robotframework 33 | 34 | *** Settings *** 35 | Library DependencyLibrary 36 | 37 | Typical usage: 38 | 39 | .. code:: robotframework 40 | 41 | *** Test cases *** 42 | Passing Test 43 | No operation 44 | 45 | A Test that Depends on "Passing Test" 46 | Depends on test Passing Test 47 | Log The rest of the keywords in this test will run as normal. 48 | 49 | When you need to declare multiple dependencies, just repeat the keyword: 50 | 51 | .. code:: robotframework 52 | 53 | *** Test cases *** 54 | Another Passing Test 55 | No operation 56 | 57 | A Test that Depends on Both "Passing Test" and "Another Passing Test" 58 | Depends on test Passing Test 59 | Depends on test Another Passing Test 60 | Log The rest of the keywords in this test will run as normal. 61 | 62 | You can also depend on the statuses of entire test suites: 63 | 64 | .. code:: robotframework 65 | 66 | *** Test cases *** 67 | A Test that Depends on an Entire Test Suite Passing 68 | Depends on suite Some Test Suite Name 69 | Log The rest of the keywords will run if that whole suite passed. 70 | 71 | Note that to depend on a suite or a test from another suite, you must 72 | either run Robot Framework with ``--listener DependencyLibrary``, or 73 | that suite must also include ``DependencyLibrary`` in its 74 | ``*** Settings ***``. 75 | 76 | Skipped Dependencies 77 | -------------------- 78 | 79 | If a dependency was skipped, the depending test is also skipped: 80 | 81 | .. code:: robotframework 82 | 83 | *** Test cases *** 84 | Skipped Test 85 | Skip This test is skipped for some reason. 86 | 87 | A Test that Depends on "Skipped Test" 88 | Depends on test Skipped Test 89 | Log The rest of the keywords (including this log) will NOT run! 90 | 91 | The skip message follows this format:: 92 | 93 | Dependency not met: test case 'Skipped Test' was skipped. 94 | 95 | 96 | Failing Dependencies 97 | -------------------- 98 | 99 | If a dependency failed, the depending test is skipped instead of 100 | redundantly failing as well: 101 | 102 | .. code:: robotframework 103 | 104 | *** Test cases *** 105 | Failing Test 106 | Fail This test failed for some reason. 107 | 108 | A Test that Depends on "Failing Test" 109 | Depends on test Failing Test 110 | Log The rest of the keywords (including this log) will NOT run! 111 | 112 | The skip message follows this format:: 113 | 114 | Dependency not met: test case 'Failing Test' failed. 115 | 116 | 117 | Mistake Warnings 118 | ---------------- 119 | 120 | If you depend on a test or suite that does not exist or has not run yet, 121 | 122 | .. code:: robotframework 123 | 124 | *** Test cases *** 125 | A Test that Depends on "Missing Test" 126 | Depends on test Missing Test 127 | 128 | the test will warn and the warning message follows this format:: 129 | 130 | Dependency not met: test case 'Missing Test' not found. 131 | 132 | If you make a test depend on itself or on the suite that contains it, 133 | 134 | .. code:: robotframework 135 | 136 | *** Test cases *** 137 | Depends on Self 138 | Depends on test Depends on Self 139 | 140 | the test will warn and the warning message follows this format:: 141 | 142 | Dependency not met: test case 'Depends on Self' mid-execution. 143 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from os import path 4 | 5 | from setuptools import setup 6 | 7 | from DependencyLibrary import __version__ 8 | 9 | project_directory = path.abspath(path.dirname(__file__)) 10 | readme_path = path.join(project_directory, 'README.rst') 11 | 12 | with open(readme_path) as readme_file: 13 | long_description = readme_file.read() 14 | 15 | setup( 16 | name='robotframework-dependencylibrary', 17 | version=__version__, 18 | description='Declare dependencies between Robot Framework tests', 19 | long_description=long_description, 20 | license='0BSD (BSD Zero Clause License)', 21 | url='https://github.com/mentalisttraceur/robotframework-dependencylibrary', 22 | author='Alexander Kozhevnikov', 23 | author_email='mentalisttraceur@gmail.com', 24 | classifiers=[ 25 | 'Development Status :: 5 - Production/Stable', 26 | 'Framework :: Robot Framework :: Library', 27 | 'Topic :: Software Development :: Testing', 28 | 'Programming Language :: Python :: 3', 29 | 'Programming Language :: Python :: 2', 30 | 'Operating System :: OS Independent', 31 | ], 32 | py_modules=['DependencyLibrary'], 33 | install_requires=['robotframework'], 34 | ) 35 | --------------------------------------------------------------------------------