├── .gitignore ├── LICENSE ├── README.md ├── conf ├── pylintrc └── setup.cfg ├── requirements.txt ├── requirements_dev.txt ├── robotframework2testrail.py ├── test ├── __init__.py ├── examples │ ├── test_suite_with_metadata.robot │ ├── test_suite_with_metadata_and_tag.robot │ ├── test_suite_with_tag.robot │ └── test_suite_without_id.robot ├── output.xml ├── test_robotframework2testrail.py └── test_testrail_utils.py ├── testrail.py └── testrail_utils.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | env/ 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *,cover 49 | .hypothesis/ 50 | 51 | # Translations 52 | *.mo 53 | *.pot 54 | 55 | # Django stuff: 56 | *.log 57 | local_settings.py 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # dotenv 85 | .env 86 | 87 | # virtualenv 88 | .venv 89 | venv/ 90 | ENV/ 91 | 92 | # Spyder project settings 93 | .spyderproject 94 | 95 | # Rope project settings 96 | .ropeproject 97 | 98 | /testrail.cfg 99 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | robotframework-testrail 2 | ======================= 3 | 4 | This script publishes results of Robot Framework in TestRail. 5 | 6 | The standard process is: 7 | Robot Framework execution => `output.xml` => This script => TestRail API 8 | 9 | 10 | Installation 11 | ------------ 12 | 13 | Tested with Python>=3. 14 | 15 | Best use with `virtualenv` (to adapt according your Python/OS version): 16 | 17 | ```cmd 18 | > virtualenv . 19 | > Scripts\activate # Windows case 20 | > pip install -r requirements.txt 21 | ``` 22 | 23 | 24 | Configuration 25 | ------------- 26 | 27 | ### Robot Framework 28 | 29 | To create the `TEST_CASE_ID` you have the possibility to use the metadata or the test's tag, `the priority is done to the tag and not the metadata`. 30 | 31 | 32 | **With Metadata:** 33 | 34 | If you want to create only one `TEST_CASE_ID` for you test, use the following method: 35 | 36 | Create a metadata `TEST_CASE_ID` in your test containing TestRail ID. 37 | 38 | Format of `TEST_CASE_ID` is : 39 | * Descriptor + an integer: `C1234`, `TestRail5678` 40 | * An integer: 1234, 5678 41 | 42 | **Example**: 43 | ```robotframework 44 | *** Settings *** 45 | Metadata TEST_CASE_ID C345 46 | 47 | *** Test Cases *** 48 | 49 | Test Example 50 | Log ${SUITE METADATA['TEST_CASE_ID']} 51 | ``` 52 | 53 | In this case, the result of Test Case C345 will be 'passed' in TestRail. 54 | 55 | 56 | **With Tags:** 57 | 58 | If you want to create one or more than `TEST_CASE_ID` for your test or tests use the following method: 59 | 60 | Create a tag `test_case_id=ID` in your test containing TestRail ID without a metadata `TEST_CASE_ID`. 61 | 62 | Format of ID is: 63 | * `C` + an integer: `C1234` 64 | * An integer: 1234, 5678 65 | 66 | **Example one test**: 67 | ```robotframework 68 | *** Test Cases *** 69 | Test 1 70 | [Tags] test_case_id=1234 critical standard 71 | ``` 72 | 73 | **Example more than one test**: 74 | ```robotframework 75 | *** Test Cases *** 76 | Test 1 77 | [Tags] test_case_id=C1234 critical standard 78 | 79 | Test 2 80 | [Tags] test_case_id=C5678 critical standard 81 | 82 | Test 3 83 | [Tags] test_case_id=C91011 critical standard 84 | ``` 85 | In this case, the results of Test 1 C1234 and Test 2 C5678 and Test 3 C91011 will be 'passed' in TestRail. 86 | 87 | **Example priority management**: 88 | ```robotframework 89 | *** Settings *** 90 | Metadata TEST_CASE_ID C345 91 | 92 | *** Test Cases *** 93 | 94 | Test Example 95 | Test 1 96 | [Tags] test_case_id=C1234 critical standard 97 | ``` 98 | In this case, the result of Test Case C1234 will be 'passed' in TestRail and not C345, priority to tag and not metatdata. 99 | 100 | **Other examples** 101 | You can find more examples in `test/examples` folder. 102 | 103 | ### TestRail configuration 104 | 105 | Create a configuration file (`testrail.cfg` for instance) containing following parameters: 106 | 107 | ```ini 108 | [API] 109 | url = https://yoururl.testrail.net/ 110 | email = user@email.com 111 | password = # May be set in command line 112 | ``` 113 | 114 | **Note** : `password` is an API key that should be generated with your TestRail account in "My Settings" section. 115 | 116 | Usage 117 | ----- 118 | 119 | ``` 120 | usage: robotframework2testrail.py [-h] --tr-config CONFIG 121 | [--tr-password API_KEY] 122 | [--tr-version VERSION] [--dryrun] 123 | [--tr-dont-publish-blocked] 124 | (--tr-run-id RUN_ID | --tr-plan-id PLAN_ID) 125 | xml_robotfwk_output 126 | 127 | Tool to publish Robot Framework results in TestRail 128 | 129 | positional arguments: 130 | xml_robotfwk_output XML output results of Robot Framework 131 | 132 | optional arguments: 133 | -h, --help show this help message and exit 134 | --tr-config CONFIG TestRail configuration file. 135 | --tr-password API_KEY 136 | API key of TestRail account with write access. 137 | --tr-version VERSION Indicate a version in Test Case result. 138 | --dryrun Run script but don't publish results. 139 | --tr-dont-publish-blocked 140 | Do not publish results of "blocked" testcases in 141 | TestRail. 142 | --tr-run-id RUN_ID Identifier of Test Run, that appears in TestRail. 143 | --tr-plan-id PLAN_ID Identifier of Test Plan, that appears in TestRail. 144 | ``` 145 | 146 | ### Example 147 | 148 | ```bash 149 | # Dry run 150 | python robotframework2testrail.py --tr-config=testrail.cfg --dryrun --tr-run-id=196 output.xml 151 | 152 | # Publish in Test Run #196 153 | python robotframework2testrail.py --tr-config=testrail.cfg --tr-run-id=196 output.xml 154 | 155 | # Publish in Test Plan #200 and dont publish "blocked" Test Cases in TestRail 156 | python robotframework2testrail.py --tr-config=testrail.cfg --tr-plan-id=200 --tr-dont-publish-blocked output.xml 157 | 158 | # Publish in Test Plan #200 with version '1.0.2' 159 | python robotframework2testrail.py --tr-config=testrail.cfg --tr-plan-id=200 --tr-version=1.0.2 output.xml 160 | 161 | # Publish with api key in command line 162 | python robotframework2testrail.py --tr-config=testrail.cfg --tr-password azertyazertyqsdfqsdf --tr-plan-id=200 output.xml 163 | 164 | ``` 165 | -------------------------------------------------------------------------------- /conf/pylintrc: -------------------------------------------------------------------------------- 1 | [MASTER] 2 | # Specify a configuration file. 3 | #rcfile= 4 | 5 | # Python code to execute, usually for sys.path manipulation such as 6 | # pygtk.require(). 7 | #init-hook= 8 | 9 | # Add files or directories to the blacklist. They should be base names, not 10 | # paths. 11 | ignore=CVS 12 | 13 | # Add files or directories matching the regex patterns to the blacklist. The 14 | # regex matches against base names, not paths. 15 | ignore-patterns= 16 | 17 | # Pickle collected data for later comparisons. 18 | persistent=yes 19 | 20 | # List of plugins (as comma separated values of python modules names) to load, 21 | # usually to register additional checkers. 22 | load-plugins= 23 | 24 | # Use multiple processes to speed up Pylint. 25 | jobs=1 26 | 27 | # Allow loading of arbitrary C extensions. Extensions are imported into the 28 | # active Python interpreter and may run arbitrary code. 29 | unsafe-load-any-extension=no 30 | 31 | # A comma-separated list of package or module names from where C extensions may 32 | # be loaded. Extensions are loading into the active Python interpreter and may 33 | # run arbitrary code 34 | extension-pkg-whitelist= 35 | 36 | # Allow optimization of some AST trees. This will activate a peephole AST 37 | # optimizer, which will apply various small optimizations. For instance, it can 38 | # be used to obtain the result of joining multiple strings with the addition 39 | # operator. Joining a lot of strings can lead to a maximum recursion error in 40 | # Pylint and this flag can prevent that. It has one side effect, the resulting 41 | # AST will be different than the one from reality. This option is deprecated 42 | # and it will be removed in Pylint 2.0. 43 | optimize-ast=no 44 | 45 | 46 | [MESSAGES CONTROL] 47 | 48 | # Only show warnings with the listed confidence levels. Leave empty to show 49 | # all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED 50 | confidence= 51 | 52 | # Enable the message, report, category or checker with the given id(s). You can 53 | # either give multiple identifier separated by comma (,) or put this option 54 | # multiple time (only on the command line, not in the configuration file where 55 | # it should appear only once). See also the "--disable" option for examples. 56 | #enable= 57 | 58 | # Disable the message, report, category or checker with the given id(s). You 59 | # can either give multiple identifiers separated by comma (,) or put this 60 | # option multiple times (only on the command line, not in the configuration 61 | # file where it should appear only once).You can also use "--disable=all" to 62 | # disable everything first and then reenable specific checks. For example, if 63 | # you want to run only the similarities checker, you can use "--disable=all 64 | # --enable=similarities". If you want to run only the classes checker, but have 65 | # no Warning level messages displayed, use"--disable=all --enable=classes 66 | # --disable=W" 67 | disable=locally-disabled,intern-builtin,raw_input-builtin,next-method-called,metaclass-assignment,old-raise-syntax,dict-view-method,long-suffix,apply-builtin,backtick,coerce-method,dict-iter-method,indexing-exception,raising-string,file-builtin,input-builtin,getslice-method,old-division,using-cmp-argument,hex-method,unichr-builtin,delslice-method,standarderror-builtin,old-octal-literal,round-builtin,nonzero-method,suppressed-message,parameter-unpacking,no-absolute-import,coerce-builtin,range-builtin-not-iterating,cmp-builtin,basestring-builtin,map-builtin-not-iterating,cmp-method,oct-method,reload-builtin,long-builtin,setslice-method,import-star-module-level,execfile-builtin,old-ne-operator,print-statement,buffer-builtin,reduce-builtin,filter-builtin-not-iterating,unicode-builtin,zip-builtin-not-iterating,useless-suppression,xrange-builtin,unpacking-in-except 68 | 69 | 70 | [REPORTS] 71 | 72 | # Set the output format. Available formats are text, parseable, colorized, msvs 73 | # (visual studio) and html. You can also give a reporter class, eg 74 | # mypackage.mymodule.MyReporterClass. 75 | output-format=text 76 | 77 | # Put messages in a separate file for each module / package specified on the 78 | # command line instead of printing them on stdout. Reports (if any) will be 79 | # written in a file name "pylint_global.[txt|html]". This option is deprecated 80 | # and it will be removed in Pylint 2.0. 81 | files-output=no 82 | 83 | # Tells whether to display a full report or only the messages 84 | reports=yes 85 | 86 | # Python expression which should return a note less than 10 (10 is the highest 87 | # note). You have access to the variables errors warning, statement which 88 | # respectively contain the number of errors / warnings messages and the total 89 | # number of statements analyzed. This is used by the global evaluation report 90 | # (RP0004). 91 | evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) 92 | 93 | # Template used to display messages. This is a python new-style format string 94 | # used to format the message information. See doc for all details 95 | msg-template={abspath}:{line}: [{msg_id}({symbol}), {obj}] {msg} 96 | 97 | 98 | [BASIC] 99 | 100 | # Good variable names which should always be accepted, separated by a comma 101 | good-names=i,j,k,ex,Run,_ 102 | 103 | # Bad variable names which should always be refused, separated by a comma 104 | bad-names=foo,bar,baz,toto,tutu,tata 105 | 106 | # Colon-delimited sets of names that determine each other's naming style when 107 | # the name regexes allow several styles. 108 | name-group= 109 | 110 | # Include a hint for the correct naming format with invalid-name 111 | include-naming-hint=no 112 | 113 | # List of decorators that produce properties, such as abc.abstractproperty. Add 114 | # to this list to register other decorators that produce valid properties. 115 | property-classes=abc.abstractproperty 116 | 117 | # Regular expression matching correct class names 118 | class-rgx=[A-Z_][a-zA-Z0-9]+$ 119 | 120 | # Naming hint for class names 121 | class-name-hint=[A-Z_][a-zA-Z0-9]+$ 122 | 123 | # Regular expression matching correct class attribute names 124 | class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 125 | 126 | # Naming hint for class attribute names 127 | class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ 128 | 129 | # Regular expression matching correct module names 130 | module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 131 | 132 | # Naming hint for module names 133 | module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ 134 | 135 | # Regular expression matching correct attribute names 136 | attr-rgx=[a-z_][a-z0-9_]{2,30}$ 137 | 138 | # Naming hint for attribute names 139 | attr-name-hint=[a-z_][a-z0-9_]{2,30}$ 140 | 141 | # Regular expression matching correct argument names 142 | argument-rgx=[a-z_][a-z0-9_]{2,30}$ 143 | 144 | # Naming hint for argument names 145 | argument-name-hint=[a-z_][a-z0-9_]{2,30}$ 146 | 147 | # Regular expression matching correct inline iteration names 148 | inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ 149 | 150 | # Naming hint for inline iteration names 151 | inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ 152 | 153 | # Regular expression matching correct function names 154 | function-rgx=[a-z_][a-z0-9_]{2,30}$ 155 | 156 | # Naming hint for function names 157 | function-name-hint=[a-z_][a-z0-9_]{2,30}$ 158 | 159 | # Regular expression matching correct method names 160 | method-rgx=[a-z_][a-z0-9_]{2,30}$ 161 | 162 | # Naming hint for method names 163 | method-name-hint=[a-z_][a-z0-9_]{2,30}$ 164 | 165 | # Regular expression matching correct variable names 166 | variable-rgx=[a-z_][a-z0-9_]{2,30}$ 167 | 168 | # Naming hint for variable names 169 | variable-name-hint=[a-z_][a-z0-9_]{2,30}$ 170 | 171 | # Regular expression matching correct constant names 172 | const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 173 | 174 | # Naming hint for constant names 175 | const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ 176 | 177 | # Regular expression which should only match function or class names that do 178 | # not require a docstring. 179 | no-docstring-rgx=^_ 180 | 181 | # Minimum line length for functions/classes that require docstrings, shorter 182 | # ones are exempt. 183 | docstring-min-length=-1 184 | 185 | 186 | [ELIF] 187 | 188 | # Maximum number of nested blocks for function / method body 189 | max-nested-blocks=5 190 | 191 | 192 | [FORMAT] 193 | 194 | # Maximum number of characters on a single line. 195 | max-line-length=120 196 | 197 | # Regexp for a line that is allowed to be longer than the limit. 198 | ignore-long-lines=^\s*(# )??$ 199 | 200 | # Allow the body of an if to be on the same line as the test if there is no 201 | # else. 202 | single-line-if-stmt=no 203 | 204 | # List of optional constructs for which whitespace checking is disabled. `dict- 205 | # separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. 206 | # `trailing-comma` allows a space between comma and closing bracket: (a, ). 207 | # `empty-line` allows space-only lines. 208 | no-space-check=trailing-comma,dict-separator 209 | 210 | # Maximum number of lines in a module 211 | max-module-lines=1000 212 | 213 | # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 214 | # tab). 215 | indent-string=' ' 216 | 217 | # Number of spaces of indent required inside a hanging or continued line. 218 | indent-after-paren=4 219 | 220 | # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. 221 | expected-line-ending-format= 222 | 223 | 224 | [LOGGING] 225 | 226 | # Logging modules to check that the string format arguments are in logging 227 | # function parameter format 228 | logging-modules=logging 229 | 230 | 231 | [MISCELLANEOUS] 232 | 233 | # List of note tags to take in consideration, separated by a comma. 234 | notes=FIXME,XXX,TODO 235 | 236 | 237 | [SIMILARITIES] 238 | 239 | # Minimum lines number of a similarity. 240 | min-similarity-lines=4 241 | 242 | # Ignore comments when computing similarities. 243 | ignore-comments=yes 244 | 245 | # Ignore docstrings when computing similarities. 246 | ignore-docstrings=yes 247 | 248 | # Ignore imports when computing similarities. 249 | ignore-imports=no 250 | 251 | 252 | [SPELLING] 253 | 254 | # Spelling dictionary name. Available dictionaries: none. To make it working 255 | # install python-enchant package. 256 | spelling-dict= 257 | 258 | # List of comma separated words that should not be checked. 259 | spelling-ignore-words= 260 | 261 | # A path to a file that contains private dictionary; one word per line. 262 | spelling-private-dict-file= 263 | 264 | # Tells whether to store unknown words to indicated private dictionary in 265 | # --spelling-private-dict-file option instead of raising a message. 266 | spelling-store-unknown-words=no 267 | 268 | 269 | [TYPECHECK] 270 | 271 | # Tells whether missing members accessed in mixin class should be ignored. A 272 | # mixin class is detected if its name ends with "mixin" (case insensitive). 273 | ignore-mixin-members=yes 274 | 275 | # List of module names for which member attributes should not be checked 276 | # (useful for modules/projects where namespaces are manipulated during runtime 277 | # and thus existing member attributes cannot be deduced by static analysis. It 278 | # supports qualified module names, as well as Unix pattern matching. 279 | ignored-modules= 280 | 281 | # List of class names for which member attributes should not be checked (useful 282 | # for classes with dynamically set attributes). This supports the use of 283 | # qualified names. 284 | ignored-classes=optparse.Values,thread._local,_thread._local 285 | 286 | # List of members which are set dynamically and missed by pylint inference 287 | # system, and so shouldn't trigger E1101 when accessed. Python regular 288 | # expressions are accepted. 289 | generated-members= 290 | 291 | # List of decorators that produce context managers, such as 292 | # contextlib.contextmanager. Add to this list to register other decorators that 293 | # produce valid context managers. 294 | contextmanager-decorators=contextlib.contextmanager 295 | 296 | 297 | [VARIABLES] 298 | 299 | # Tells whether we should check for unused import in __init__ files. 300 | init-import=yes 301 | 302 | # A regular expression matching the name of dummy variables (i.e. expectedly 303 | # not used). 304 | dummy-variables-rgx=(_+[a-zA-Z0-9]*?$)|dummy 305 | 306 | # List of additional names supposed to be defined in builtins. Remember that 307 | # you should avoid to define new builtins when possible. 308 | additional-builtins= 309 | 310 | # List of strings which can identify a callback function by name. A callback 311 | # name must start or end with one of those strings. 312 | callbacks=cb_,_cb 313 | 314 | # List of qualified module names which can have objects that can redefine 315 | # builtins. 316 | redefining-builtins-modules=six.moves,future.builtins 317 | 318 | 319 | [CLASSES] 320 | 321 | # List of method names used to declare (i.e. assign) instance attributes. 322 | defining-attr-methods=__init__,__new__,setUp 323 | 324 | # List of valid names for the first argument in a class method. 325 | valid-classmethod-first-arg=cls 326 | 327 | # List of valid names for the first argument in a metaclass class method. 328 | valid-metaclass-classmethod-first-arg=mcs 329 | 330 | # List of member names, which should be excluded from the protected access 331 | # warning. 332 | exclude-protected=_asdict,_fields,_replace,_source,_make 333 | 334 | 335 | [DESIGN] 336 | 337 | # Maximum number of arguments for function / method 338 | max-args=5 339 | 340 | # Argument names that match this expression will be ignored. Default to name 341 | # with leading underscore 342 | ignored-argument-names=_.* 343 | 344 | # Maximum number of locals for function / method body 345 | max-locals=15 346 | 347 | # Maximum number of return / yield for function / method body 348 | max-returns=6 349 | 350 | # Maximum number of branch for function / method body 351 | max-branches=12 352 | 353 | # Maximum number of statements in function / method body 354 | max-statements=50 355 | 356 | # Maximum number of parents for a class (see R0901). 357 | max-parents=7 358 | 359 | # Maximum number of attributes for a class (see R0902). 360 | max-attributes=7 361 | 362 | # Minimum number of public methods for a class (see R0903). 363 | min-public-methods=2 364 | 365 | # Maximum number of public methods for a class (see R0904). 366 | max-public-methods=20 367 | 368 | # Maximum number of boolean expressions in a if statement 369 | max-bool-expr=5 370 | 371 | 372 | [IMPORTS] 373 | 374 | # Deprecated modules which should not be used, separated by a comma 375 | deprecated-modules=optparse 376 | 377 | # Create a graph of every (i.e. internal and external) dependencies in the 378 | # given file (report RP0402 must not be disabled) 379 | import-graph= 380 | 381 | # Create a graph of external dependencies in the given file (report RP0402 must 382 | # not be disabled) 383 | ext-import-graph= 384 | 385 | # Create a graph of internal dependencies in the given file (report RP0402 must 386 | # not be disabled) 387 | int-import-graph= 388 | 389 | # Force import order to recognize a module as part of the standard 390 | # compatibility libraries. 391 | known-standard-library= 392 | 393 | # Force import order to recognize a module as part of a third party library. 394 | known-third-party=enchant 395 | 396 | # Analyse import fallback blocks. This can be used to support both Python 2 and 397 | # 3 compatible code, which means that the block might have code that exists 398 | # only in one or another interpreter, leading to false positives when analysed. 399 | analyse-fallback-blocks=no 400 | 401 | 402 | [EXCEPTIONS] 403 | 404 | # Exceptions that will emit a warning when being caught. Defaults to 405 | # "Exception" 406 | overgeneral-exceptions=Exception 407 | -------------------------------------------------------------------------------- /conf/setup.cfg: -------------------------------------------------------------------------------- 1 | [yapf] 2 | based_on_style = pep8 3 | spaces_before_comment = 4 4 | column_limit = 120 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | colorama>=0.3.9 -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | -r requirements.txt 2 | 3 | astroid==1.5.3 4 | coverage==4.4.1 5 | isort==4.2.15 6 | lazy-object-proxy==1.3.1 7 | mccabe==0.6.1 8 | py==1.10.0 9 | pylint==1.7.2 10 | pytest==3.1.3 11 | pytest-cov==2.5.1 12 | six==1.10.0 13 | wrapt==1.10.10 14 | yapf==0.16.3 -------------------------------------------------------------------------------- /robotframework2testrail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: UTF-8 -*- 3 | """ Tool to publish Robot Framework results in TestRail """ 4 | import argparse 5 | import configparser 6 | import datetime 7 | import logging 8 | import os 9 | import re 10 | import sys 11 | import time 12 | 13 | import testrail 14 | from colorama import Fore, Style, init 15 | from robot.api import ExecutionResult, ResultVisitor 16 | from testrail_utils import TestRailApiUtils 17 | 18 | # pylint: disable=logging-format-interpolation 19 | 20 | PATH = os.getcwd() 21 | 22 | COMMENT_SIZE_LIMIT = 1000 23 | 24 | # Configure the logging 25 | LOG_FORMAT = '%(asctime)-15s %(levelname)-10s %(message)s' 26 | logging.basicConfig(filename=os.path.join(PATH, 'robotframework2testrail.log'), format=LOG_FORMAT, level=logging.DEBUG) 27 | CONSOLE_HANDLER = logging.StreamHandler() 28 | CONSOLE_HANDLER.setLevel(logging.INFO) 29 | CONSOLE_HANDLER.setFormatter(logging.Formatter('%(message)s')) 30 | logging.getLogger().addHandler(CONSOLE_HANDLER) 31 | 32 | 33 | class TestRailResultVisitor(ResultVisitor): 34 | """ Implement a `Visitor` that retrieves TestRail ID from Robot Framework Result """ 35 | 36 | def __init__(self): 37 | """ Init """ 38 | self.result_testcase_list = [] 39 | 40 | def end_suite(self, suite): 41 | """ Called when suite end """ 42 | for _suite, test, test_case_id in self._get_test_case_id_from_suite(suite): 43 | self._append_testrail_result(_suite, test, test_case_id) 44 | 45 | @staticmethod 46 | def _get_test_case_id_from_suite(suite): 47 | """ Retrieve list of Test Case ID from a suite 48 | Manage both case: ID in metadata or in tags. 49 | """ 50 | testcase_id = 0 51 | result = [] 52 | # Retrieve test_case_id from metadata 53 | for metadata in suite.metadata: 54 | if metadata == 'TEST_CASE_ID': 55 | testcase_id = suite.metadata['TEST_CASE_ID'] 56 | break # We only take the first ID found 57 | # Retrieve test_case_ids from tags 58 | for test in suite.tests: 59 | test_case_ids_from_tags = TestRailResultVisitor._get_test_case_ids_from_tags(test.tags) 60 | if test_case_ids_from_tags: 61 | for tcid in test_case_ids_from_tags: 62 | result.append((test.name, test, tcid)) 63 | logging.debug("Use TestRail ID from tag: ID = %s", tcid) 64 | else: 65 | if testcase_id: 66 | result.append((suite.name, test, testcase_id)) 67 | logging.debug("Use TestRail ID from metadata: ID = %s", testcase_id) 68 | return result 69 | 70 | @staticmethod 71 | def _get_test_case_ids_from_tags(tags): 72 | """ Retrieve all test case tags found in the list """ 73 | test_case_list = [] 74 | for tag in tags: 75 | if re.findall("(test_case_id=[C]?[0-9]+)", tag): 76 | test_case_list.append(tag[len('test_case_id='):]) 77 | return test_case_list 78 | 79 | def _append_testrail_result(self, name, test, testcase_id): 80 | """ Append a result in TestRail format """ 81 | comment = None 82 | if test.message: 83 | comment = test.message 84 | # Indent text to avoid string formatting by TestRail. Limit size of comment. 85 | comment = "# Robot Framework result: #\n " + comment[:COMMENT_SIZE_LIMIT].replace('\n', '\n ') 86 | comment += '\n...\nLog truncated' if len(str(comment)) > COMMENT_SIZE_LIMIT else '' 87 | duration = 0 88 | if test.starttime and test.endtime: 89 | td_duration = datetime.datetime.strptime(test.endtime + '000', '%Y%m%d %H:%M:%S.%f')\ 90 | - datetime.datetime.strptime(test.starttime + '000', '%Y%m%d %H:%M:%S.%f') 91 | duration = round(td_duration.total_seconds()) 92 | duration = 1 if (duration < 1) else duration # TestRail API doesn't manage msec (min value=1s) 93 | self.result_testcase_list.append({ 94 | 'id': testcase_id, 95 | 'status': test.status, 96 | 'name': name, 97 | 'comment': comment, 98 | 'duration': duration 99 | }) 100 | 101 | 102 | def get_testcases(xml_robotfwk_output): 103 | """ Return the list of Testcase ID with status """ 104 | result = ExecutionResult(xml_robotfwk_output, include_keywords=False) 105 | visitor = TestRailResultVisitor() 106 | result.visit(visitor) 107 | return visitor.result_testcase_list 108 | 109 | 110 | def publish_results(api, testcases, run_id=0, plan_id=0, version='', publish_blocked=True): 111 | # pylint: disable=too-many-arguments, too-many-branches 112 | """ Update testcases with provided Test Run or Test Plan 113 | 114 | :param api: Client to TestRail API 115 | :param testcases: List of testcases with status, returned by `get_testcases` 116 | :param run_id: TestRail ID of Test Run to update 117 | :param plan_id: TestRail ID of Test Plan to update 118 | :param version: Version to indicate in Test Case result 119 | :param publish_blocked: If False, results of "blocked" Test cases in TestRail are not published 120 | :return: True if publishing was done. False in case of error. 121 | """ 122 | if run_id: 123 | if api.is_testrun_available(run_id): 124 | count = 0 125 | logging.info('Publish in Test Run #%d', run_id) 126 | testcases_in_testrun_list = api.get_tests(run_id) 127 | 128 | # Filter tests present in Test Run 129 | case_id_in_testrun_list = [str(tc['case_id']) for tc in testcases_in_testrun_list] 130 | testcases = [ 131 | testcase for testcase in testcases if testcase['id'].replace('C', '') in case_id_in_testrun_list 132 | ] 133 | 134 | # Filter "blocked" tests 135 | if publish_blocked is False: 136 | logging.info('Option "Don\'t publish blocked testcases" activated') 137 | blocked_tests_list = [ 138 | test.get('case_id') for test in testcases_in_testrun_list if test.get('status_id') == 2 139 | ] 140 | logging.info('Blocked testcases excluded: %s', ', '.join(str(elt) for elt in blocked_tests_list)) 141 | testcases = [ 142 | testcase for testcase in testcases 143 | if api.extract_testcase_id(testcase.get('id')) not in blocked_tests_list 144 | ] 145 | try: 146 | result = api.add_results(run_id, version, testcases) 147 | logging.info('%d result(s) published in Test Run #%d.', len(result), run_id) 148 | except testrail.APIError: 149 | logging.exception('Error while publishing results') 150 | else: 151 | logging.error('Test Run #%d is is not available', run_id) 152 | return False 153 | 154 | elif plan_id: 155 | if api.is_testplan_available(plan_id): 156 | logging.info('Publish in Test Plan #%d', plan_id) 157 | for _run_id in api.get_available_testruns(plan_id): 158 | publish_results(api, testcases, run_id=_run_id, version=version, publish_blocked=publish_blocked) 159 | else: 160 | logging.error('Test Plan #%d is is not available', plan_id) 161 | return False 162 | 163 | else: 164 | logging.error("You have to indicate a Test Run or a Test Plan ID") 165 | print(Fore.LIGHTRED_EX + 'ERROR') 166 | return False 167 | 168 | return True 169 | 170 | 171 | def pretty_print(testcases): 172 | """ Pretty print a list of testcases """ 173 | for testcase in testcases: 174 | pretty_print_testcase(testcase) 175 | print(Fore.RESET) 176 | 177 | 178 | def pretty_print_testcase(testcase, error=''): 179 | """ Pretty print a testcase """ 180 | if error: 181 | msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \ 182 | Fore.MAGENTA + '{status}' + Fore.RESET + '\t' + \ 183 | '{name}\t=> ' + str(error) 184 | elif testcase['status'] == 'PASS': 185 | msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \ 186 | Fore.LIGHTGREEN_EX + '{status}' + Fore.RESET + '\t' + \ 187 | '{name}\t' 188 | else: 189 | msg_template = Style.BRIGHT + '{id}' + Style.RESET_ALL + '\t' + \ 190 | Fore.LIGHTRED_EX + '{status}' + Fore.RESET + '\t' + \ 191 | '{name}\t' 192 | print(msg_template.format(**testcase), end=Style.RESET_ALL) 193 | 194 | 195 | def options(): 196 | """ Manage options """ 197 | parser = argparse.ArgumentParser(prog='robotframework2testrail.py', description=__doc__) 198 | parser.add_argument( 199 | 'xml_robotfwk_output', 200 | nargs=1, 201 | type=argparse.FileType('r', encoding='UTF-8'), 202 | help='XML output results of Robot Framework') 203 | parser.add_argument( 204 | '--tr-config', 205 | dest='config', 206 | metavar='CONFIG', 207 | type=argparse.FileType('r', encoding='UTF-8'), 208 | required=True, 209 | help='TestRail configuration file.') 210 | parser.add_argument( 211 | '--tr-password', dest='password', metavar='API_KEY', help='API key of TestRail account with write access.') 212 | parser.add_argument( 213 | '--tr-version', dest='version', metavar='VERSION', help='Indicate a version in Test Case result.') 214 | parser.add_argument('--dryrun', action='store_true', help='Run script but don\'t publish results.') 215 | parser.add_argument( 216 | '--tr-dont-publish-blocked', 217 | action='store_true', 218 | help='Do not publish results of "blocked" testcases in TestRail.') 219 | 220 | group = parser.add_mutually_exclusive_group(required=True) 221 | group.add_argument( 222 | '--tr-run-id', 223 | dest='run_id', 224 | action='store', 225 | type=int, 226 | default=None, 227 | help='Identifier of Test Run, that appears in TestRail.') 228 | group.add_argument( 229 | '--tr-plan-id', 230 | dest='plan_id', 231 | action='store', 232 | type=int, 233 | default=None, 234 | help='Identifier of Test Plan, that appears in TestRail.') 235 | 236 | opt = parser.parse_known_args() 237 | if opt[1]: 238 | logging.warning('Unknown options: %s', opt[1]) 239 | return opt[0] 240 | 241 | 242 | if __name__ == '__main__': 243 | # Global init 244 | init() # colorama 245 | 246 | # Manage options 247 | ARGUMENTS = options() 248 | 249 | TESTCASES = get_testcases(ARGUMENTS.xml_robotfwk_output[0].name) 250 | 251 | if ARGUMENTS.dryrun: 252 | pretty_print(TESTCASES) 253 | print(Fore.GREEN + 'OK') 254 | sys.exit() 255 | 256 | # Init global variables 257 | CONFIG = configparser.ConfigParser() 258 | CONFIG.read_file(ARGUMENTS.config) 259 | URL = CONFIG.get('API', 'url') 260 | EMAIL = CONFIG.get('API', 'email') 261 | VERSION = ARGUMENTS.version 262 | PUBLISH_BLOCKED = not ARGUMENTS.tr_dont_publish_blocked 263 | if ARGUMENTS.password: 264 | PASSWORD = ARGUMENTS.password 265 | else: 266 | PASSWORD = CONFIG.get('API', 'password') 267 | 268 | logging.debug('Connection info: URL=%s, EMAIL=%s, PASSWORD=%s', URL, EMAIL, len(PASSWORD) * '*') 269 | 270 | # Init API 271 | API = TestRailApiUtils(URL) 272 | API.user = EMAIL 273 | API.password = PASSWORD 274 | 275 | # Main 276 | if publish_results( 277 | API, 278 | TESTCASES, 279 | run_id=ARGUMENTS.run_id, 280 | plan_id=ARGUMENTS.plan_id, 281 | version=VERSION, 282 | publish_blocked=PUBLISH_BLOCKED): 283 | print(Fore.GREEN + 'OK' + Fore.RESET) 284 | sys.exit() 285 | else: 286 | print(Fore.LIGHTRED_EX + 'ERROR' + Fore.RESET) 287 | sys.exit(1) 288 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: UTF-8 -*- 3 | """ Unit tests of `robotframework-testrail` """ 4 | -------------------------------------------------------------------------------- /test/examples/test_suite_with_metadata.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Metadata TEST_CASE_ID C344 3 | 4 | *** Test Cases *** 5 | Test With Id_344 From Metadata 6 | [Tags] NONE 7 | Log Only With Metadata 8 | 9 | Test2 With Id_344 From Metadata 10 | [Tags] NONE 11 | Fail Only With Metadata 12 | -------------------------------------------------------------------------------- /test/examples/test_suite_with_metadata_and_tag.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Metadata TEST_CASE_ID C345 3 | 4 | *** Test Cases *** 5 | Test With Id 345 From Metadata 6 | [Tags] NONE 7 | Log With Metadata 8 | 9 | Test With Id 366 From Tag 10 | [Tags] TAG1 TAG2 test_case_id=C366 11 | Log With Metadata And Tag 12 | -------------------------------------------------------------------------------- /test/examples/test_suite_with_tag.robot: -------------------------------------------------------------------------------- 1 | *** Test Cases *** 2 | Test With Id 347 From Tag 3 | [Tags] TAG1 test_case_id=C347 TAG2 4 | Fail Only With Tag 5 | 6 | Test With Id 348 From Tag 7 | [Tags] TAG1 TAG2 test_case_id=348 8 | Log Only With Tag 9 | 10 | Test Without Id 11 | [Tags] TAG1 TAG2 12 | Fail With No Tag 13 | -------------------------------------------------------------------------------- /test/examples/test_suite_without_id.robot: -------------------------------------------------------------------------------- 1 | *** Test Cases *** 2 | Test Without Id 3 | [Tags] NONE 4 | Log Without Any Test Case ID 5 | -------------------------------------------------------------------------------- /test/output.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | Logs the given message with the given level. 10 | 11 | Only With Metadata 12 | 13 | Only With Metadata 14 | 15 | 16 | 18 | 19 | 20 | 21 | Fails the test with the given message and optionally alters its tags. 22 | 23 | Only With Metadata 24 | 25 | Only With Metadata 26 | Traceback (most recent call last): 27 | None 28 | 29 | 30 | 31 | 32 | Only With Metadata 33 | 34 | 35 | 36 | C344 37 | 38 | 39 | 40 | 43 | 44 | 45 | Logs the given message with the given level. 46 | 47 | With Metadata 48 | 49 | With Metadata 50 | 51 | 52 | 54 | 55 | 56 | 57 | Logs the given message with the given level. 58 | 59 | With Metadata And Tag 60 | 61 | With Metadata And Tag 62 | 63 | 64 | 65 | TAG1 66 | TAG2 67 | test_case_id=C366 68 | 69 | 71 | 72 | 73 | C345 74 | 75 | 76 | 77 | 80 | 81 | 82 | Fails the test with the given message and optionally alters its tags. 83 | 84 | Only With Tag 85 | 86 | Only With Tag 87 | Traceback (most recent call last): 88 | None 89 | 90 | 91 | 92 | 93 | TAG1 94 | TAG2 95 | test_case_id=C347 96 | 97 | 98 | Only With Tag 99 | 100 | 101 | 102 | 103 | Logs the given message with the given level. 104 | 105 | Only With Tag 106 | 107 | Only With Tag 108 | 109 | 110 | 111 | TAG1 112 | TAG2 113 | test_case_id=348 114 | 115 | 117 | 118 | 119 | 120 | Fails the test with the given message and optionally alters its tags. 121 | 122 | With No Tag 123 | 124 | With No Tag 125 | Traceback (most recent call last): 126 | None 127 | 128 | 129 | 130 | 131 | TAG1 132 | TAG2 133 | 134 | 135 | With No Tag 136 | 137 | 138 | 139 | 140 | 143 | 144 | 145 | Logs the given message with the given level. 146 | 147 | Without Any Test Case ID 148 | 149 | Without Any Test Case ID 150 | 151 | 152 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | Critical Tests 162 | All Tests 163 | 164 | 165 | TAG1 166 | TAG2 167 | test_case_id=348 168 | test_case_id=C347 169 | test_case_id=C366 170 | 171 | 172 | Examples 173 | Examples.Test Suite With Metadata 174 | Examples.Test Suite With Metadata 175 | And Tag 176 | 177 | Examples.Test Suite With Tag 178 | Examples.Test Suite Without Id 179 | 180 | 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /test/test_robotframework2testrail.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: UTF-8 -*- 3 | """ Test of mod:`robotframework2testrail` """ 4 | import os 5 | from unittest.mock import Mock, call 6 | 7 | import robotframework2testrail 8 | from testrail_utils import TestRailApiUtils 9 | 10 | TESTRAIL_URL = 'https://example.testrail.net' 11 | 12 | RESULTS = [{ 13 | 'status': 'PASS', 14 | 'id': 'C344', 15 | 'comment': None, 16 | 'name': 'Test Suite With Metadata', 17 | 'duration': 1 18 | }, { 19 | 'status': 'FAIL', 20 | 'id': 'C344', 21 | 'comment': '# Robot Framework result: #\n \n Only With Metadata\n ', 22 | 'name': 'Test Suite With Metadata', 23 | 'duration': 60 24 | }, { 25 | 'status': 'PASS', 26 | 'id': 'C345', 27 | 'comment': None, 28 | 'name': 'Test Suite With Metadata And Tag', 29 | 'duration': 1 30 | }, { 31 | 'status': 'PASS', 32 | 'id': 'C366', 33 | 'comment': None, 34 | 'name': 'Test With Id 366 From Tag', 35 | 'duration': 3600 36 | }, { 37 | 'status': 'FAIL', 38 | 'id': 'C347', 39 | 'comment': '# Robot Framework result: #\n \n Only With Tag\n ', 40 | 'name': 'Test With Id 347 From Tag', 41 | 'duration': 24 * 3600 42 | }, { 43 | 'status': 'PASS', 44 | 'id': '348', 45 | 'comment': None, 46 | 'name': 'Test With Id 348 From Tag', 47 | 'duration': 1 48 | }] 49 | 50 | 51 | def test_get_testcases(): 52 | """ Test of function `get_testcases` """ 53 | results = robotframework2testrail.get_testcases(os.path.join(robotframework2testrail.PATH, 'test', 'output.xml')) 54 | assert results == RESULTS 55 | 56 | 57 | def test_publish_testrun(): 58 | """ Test of function `publish_results` """ 59 | api = Mock() 60 | api.get_tests.return_value = [{'case_id': 344}, {'case_id': 345}] # Other case_ids are missing 61 | testrun_id = 100 62 | robotframework2testrail.publish_results(api, RESULTS, run_id=testrun_id, version='1.2.3.4') 63 | api.is_testrun_available.assert_called_with(testrun_id) 64 | assert api.add_result.call_args_list[0] == call(testrun_id, RESULTS[0]) 65 | assert api.add_result.call_args_list[1] == call(testrun_id, RESULTS[1]) 66 | assert api.add_result.call_args_list[2] == call(testrun_id, RESULTS[2]) 67 | assert len(api.add_result.call_args_list) == 3 # Other case_ids are missing so not published 68 | 69 | 70 | def test_publish_testplan(): 71 | """ Test of function `publish_results` """ 72 | api = Mock() 73 | api.get_tests.return_value = [{ 74 | 'case_id': 9876 75 | }, { 76 | 'case_id': 344 77 | }, { 78 | 'case_id': 345 79 | }, { 80 | 'case_id': 366 81 | }, { 82 | 'case_id': 348 83 | }] 84 | api.get_available_testruns.return_value = [101, 102] 85 | robotframework2testrail.publish_results(api, RESULTS, plan_id=100) 86 | assert api.add_result.call_args_list[0] == call(101, RESULTS[0]) 87 | assert api.add_result.call_args_list[1] == call(101, RESULTS[1]) 88 | assert api.add_result.call_args_list[2] == call(101, RESULTS[2]) 89 | assert api.add_result.call_args_list[3] == call(101, RESULTS[3]) 90 | assert api.add_result.call_args_list[4] == call(101, RESULTS[5]) 91 | assert api.add_result.call_args_list[5] == call(102, RESULTS[0]) 92 | assert api.add_result.call_args_list[6] == call(102, RESULTS[1]) 93 | assert api.add_result.call_args_list[7] == call(102, RESULTS[2]) 94 | assert api.add_result.call_args_list[8] == call(102, RESULTS[3]) 95 | assert api.add_result.call_args_list[9] == call(102, RESULTS[5]) 96 | 97 | 98 | def test_dont_publish_blocked(): 99 | """ Test when blocked testcases are not published """ 100 | api = Mock() 101 | testrun_id = 100 102 | api.get_tests.return_value = [{ 103 | 'case_id': 344, 104 | 'status_id': 1 105 | }, { 106 | 'case_id': 345, 107 | 'status_id': 2 108 | }, { 109 | 'case_id': 348, 110 | 'status_id': 1 111 | }] 112 | api.extract_testcase_id = TestRailApiUtils.extract_testcase_id # don't mock this method 113 | robotframework2testrail.publish_results(api, RESULTS, run_id=100, publish_blocked=False) 114 | assert len(api.add_result.call_args_list) == 3 115 | assert api.add_result.call_args_list[0] == call(testrun_id, RESULTS[0]) 116 | assert api.add_result.call_args_list[1] == call(testrun_id, RESULTS[1]) 117 | assert api.add_result.call_args_list[2] == call(testrun_id, RESULTS[5]) 118 | -------------------------------------------------------------------------------- /test/test_testrail_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: UTF-8 -*- 3 | """ Test of module mod:`testrail_utils` """ 4 | from unittest.mock import Mock 5 | 6 | import pytest 7 | 8 | import testrail_utils as tr 9 | from testrail import APIError 10 | 11 | TESTRAIL_URL = 'https://example.testrail.net' 12 | 13 | TESTCASES = [{ 14 | 'id': 'C9876', 15 | 'name': 'Testrail2', 16 | 'status': 'FAIL', 17 | 'comment': 'ERROR!' 18 | }, { 19 | 'id': 'C344', 20 | 'name': 'Testrail', 21 | 'status': 'PASS' 22 | }, { 23 | 'id': 'C1111', 24 | 'name': 'Testrail3', 25 | 'status': 'PASS', 26 | 'version': '1.0.2', 27 | 'duration': 60 28 | }] 29 | 30 | TESTPLAN = { 31 | "id": 32 | 58, 33 | "is_completed": 34 | False, 35 | "entries": [{ 36 | "id": "ce2f3c8f-9899-47b9-a6da-db59a66fb794", 37 | "name": "Test Run 5/23/2017", 38 | "runs": [{ 39 | "id": 59, 40 | "name": "Test Run 1", 41 | "is_completed": False, 42 | }] 43 | }, { 44 | "id": "084f680c-f87a-402e-92be-d9cc2359b9a7", 45 | "name": "Test Run 5/23/2017", 46 | "runs": [{ 47 | "id": 60, 48 | "name": "Test Run 2", 49 | "is_completed": True, 50 | }] 51 | }, { 52 | "id": "775740ff-1ba3-4313-a9df-3acd9d5ef967", 53 | "name": "Test Run 3", 54 | "runs": [{ 55 | "id": 61, 56 | "is_completed": False, 57 | }] 58 | }] 59 | } 60 | 61 | 62 | @pytest.fixture 63 | def api(): 64 | """ Return access to TestRail API """ 65 | inst = tr.TestRailApiUtils(TESTRAIL_URL) 66 | inst.send_get = Mock() 67 | inst.send_post = Mock() 68 | return inst 69 | 70 | 71 | def test_add_result(api): # pylint: disable=redefined-outer-name 72 | """ Test of method `add_results` """ 73 | api.add_result(1, TESTCASES[0]) 74 | api.send_post.assert_called_once_with( 75 | tr.API_ADD_RESULT_CASE_URL.format(run_id=1, case_id=9876), {'status_id': 5, 76 | 'comment': 'ERROR!'}) 77 | 78 | api.add_result(1, TESTCASES[2]) 79 | api.send_post.assert_called_with( 80 | tr.API_ADD_RESULT_CASE_URL.format(run_id=1, case_id=1111), 81 | {'status_id': 1, 82 | 'version': '1.0.2', 83 | 'elapsed': '60s'}) 84 | 85 | 86 | def test_is_testrun_available(api): # pylint: disable=redefined-outer-name 87 | """ Test of method `is_testrun_available` """ 88 | api.send_get.return_value = {'is_completed': False} 89 | assert api.is_testrun_available(1) is True 90 | 91 | api.send_get.side_effect = APIError('Test Run not found') 92 | assert api.is_testrun_available(1) is False 93 | 94 | api.send_get.return_value = {'is_completed': True} 95 | assert api.is_testrun_available(1) is False 96 | 97 | 98 | def test_is_testplan_available(api): # pylint: disable=redefined-outer-name 99 | """ Test of method `is_testplan_available` """ 100 | api.send_get.return_value = {'is_completed': False} 101 | assert api.is_testplan_available(10) is True 102 | 103 | api.send_get.side_effect = APIError('Test Plan not found') 104 | assert api.is_testplan_available(10) is False 105 | 106 | api.send_get.return_value = {'is_completed': True} 107 | assert api.is_testplan_available(10) is False 108 | 109 | 110 | def test_get_available_testruns(api): # pylint: disable=redefined-outer-name 111 | """ Test of method `get_available_testruns` """ 112 | api.send_get.return_value = TESTPLAN 113 | assert api.get_available_testruns(100) == [59, 61] 114 | 115 | 116 | def test_extract_testcase_id(api): # pylint: disable=redefined-outer-name 117 | """ Test of method `extract_testcase_id` """ 118 | assert api.extract_testcase_id('C1234') == 1234 119 | assert api.extract_testcase_id('c1234') == 1234 120 | assert api.extract_testcase_id('C1234 C9874') == 1234 121 | assert api.extract_testcase_id('1234') == 1234 122 | 123 | # Error cases 124 | assert api.extract_testcase_id('') is None 125 | assert api.extract_testcase_id('test') is None 126 | assert api.extract_testcase_id('test C1234') is None 127 | 128 | 129 | def test_get_tests(api): # pylint: disable=redefined-outer-name 130 | """ Test of method `extract_testcase_id` """ 131 | run_id = 100 132 | api.get_tests(testrun_id=run_id) 133 | print(api.send_get.call_args_list) 134 | api.send_get.assert_called_once_with(tr.API_GET_TESTS_URL.format(run_id=run_id)) 135 | -------------------------------------------------------------------------------- /testrail.py: -------------------------------------------------------------------------------- 1 | # 2 | # TestRail API binding for Python 3.x (API v2, available since 3 | # TestRail 3.0) 4 | # 5 | # Learn more: 6 | # 7 | # http://docs.gurock.com/testrail-api2/start 8 | # http://docs.gurock.com/testrail-api2/accessing 9 | # 10 | # Copyright Gurock Software GmbH. See license.md for details. 11 | # 12 | # pylint: skip-file 13 | import urllib.request, urllib.error 14 | import json, base64 15 | import time 16 | import logging 17 | 18 | 19 | class APIClient: 20 | def __init__(self, base_url): 21 | self.user = '' 22 | self.password = '' 23 | if not base_url.endswith('/'): 24 | base_url += '/' 25 | self.__url = base_url + 'index.php?/api/v2/' 26 | 27 | # 28 | # Send Get 29 | # 30 | # Issues a GET request (read) against the API and returns the result 31 | # (as Python dict). 32 | # 33 | # Arguments: 34 | # 35 | # uri The API method to call including parameters 36 | # (e.g. get_case/1) 37 | # 38 | def send_get(self, uri): 39 | return self.__send_request('GET', uri, None) 40 | 41 | # 42 | # Send POST 43 | # 44 | # Issues a POST request (write) against the API and returns the result 45 | # (as Python dict). 46 | # 47 | # Arguments: 48 | # 49 | # uri The API method to call including parameters 50 | # (e.g. add_case/1) 51 | # data The data to submit as part of the request (as 52 | # Python dict, strings must be UTF-8 encoded) 53 | # 54 | def send_post(self, uri, data): 55 | return self.__send_request('POST', uri, data) 56 | 57 | def __send_request(self, method, uri, data): 58 | url = self.__url + uri 59 | request = urllib.request.Request(url) 60 | if (method == 'POST'): 61 | request.data = bytes(json.dumps(data), 'utf-8') 62 | auth = str(base64.b64encode(bytes('%s:%s' % (self.user, self.password), 'utf-8')), 'ascii').strip() 63 | request.add_header('Authorization', 'Basic %s' % auth) 64 | request.add_header('Content-Type', 'application/json') 65 | 66 | e = None 67 | try: 68 | response = urllib.request.urlopen(request).read() 69 | except urllib.error.HTTPError as ex: 70 | response = ex.read() 71 | e = ex 72 | 73 | if response: 74 | result = json.loads(response.decode()) 75 | else: 76 | result = {} 77 | 78 | if e != None: 79 | if e.code == 429: # Too many requests 80 | pause = int(e.headers.get('Retry-After', 60)) 81 | logging.warning("Too many requests: pause for %ss", pause) 82 | time.sleep(pause) 83 | return self.__send_request(method, uri, data) 84 | else: 85 | if result and 'error' in result: 86 | error = '"' + result['error'] + '"' 87 | else: 88 | error = 'No additional error message received' 89 | raise APIError('TestRail API returned HTTP %s (%s)' % (e.code, error)) 90 | 91 | return result 92 | 93 | 94 | class APIError(Exception): 95 | pass 96 | -------------------------------------------------------------------------------- /testrail_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: UTF-8 -*- 3 | """ Various useful class using TestRail API """ 4 | import logging 5 | import string 6 | 7 | import testrail 8 | 9 | API_ADD_RESULT_CASE_URL = 'add_result_for_case/{run_id}/{case_id}' 10 | API_ADD_RESULT_CASES_URL = 'add_results_for_cases/{run_id}' 11 | API_GET_RUN_URL = 'get_run/{run_id}' 12 | API_GET_PLAN_URL = 'get_plan/{plan_id}' 13 | API_GET_TESTS_URL = 'get_tests/{run_id}' 14 | 15 | ROBOTFWK_TO_TESTRAIL_STATUS = { 16 | "PASS": 1, 17 | "FAIL": 5, 18 | } 19 | 20 | 21 | class TestRailApiUtils(testrail.APIClient): 22 | """ Class adding facilities to manipulate Testrail API """ 23 | 24 | def add_result(self, testrun_id, testcase_info): 25 | """ Add a result to the given Test Run 26 | 27 | :param testrun_id: Testrail ID of the Test Run to feed 28 | :param testcase_info: Dict containing info on testcase 29 | 30 | """ 31 | data = {'status_id': ROBOTFWK_TO_TESTRAIL_STATUS[testcase_info.get('status')]} 32 | if 'version' in testcase_info: 33 | data['version'] = testcase_info.get('version') 34 | if 'comment' in testcase_info: 35 | data['comment'] = testcase_info.get('comment') 36 | if 'duration' in testcase_info: 37 | data['elapsed'] = str(testcase_info.get('duration')) + 's' 38 | testcase_id = self.extract_testcase_id(testcase_info['id']) 39 | if not testcase_id: 40 | logging.error('Testcase ID is bad formatted: "%s"', testcase_info['id']) 41 | return None 42 | 43 | return self.send_post(API_ADD_RESULT_CASE_URL.format(run_id=testrun_id, case_id=testcase_id), data) 44 | 45 | def add_results(self, testrun_id, version, testcase_infos): 46 | """ Add a results to the given Test Run 47 | 48 | :param testrun_id: Testrail ID of the Test Run to feed 49 | :param version: Test version 50 | :param testcase_infos: List of dict containing info on testcase 51 | 52 | """ 53 | data = [] 54 | for testcase_info in testcase_infos: 55 | testcase_data = { 56 | 'status_id': ROBOTFWK_TO_TESTRAIL_STATUS[testcase_info.get('status')] 57 | } 58 | if version: 59 | testcase_data['version'] = version 60 | if 'comment' in testcase_info: 61 | testcase_data['comment'] = testcase_info.get('comment') 62 | if 'duration' in testcase_info: 63 | testcase_data['elapsed'] = str(testcase_info.get('duration')) + 's' 64 | testcase_id = self.extract_testcase_id(testcase_info['id']) 65 | if not testcase_id: 66 | logging.error('Testcase ID is bad formatted: "%s"', testcase_info['id']) 67 | return None 68 | testcase_data['case_id'] = testcase_id 69 | data.append(testcase_data) 70 | 71 | return self.send_post(API_ADD_RESULT_CASES_URL.format(run_id=testrun_id), {'results': data}) 72 | 73 | def is_testrun_available(self, testrun_id): 74 | """ Ask if Test Run is available in TestRail. 75 | 76 | :param testplan_id: Testrail ID of the Test Run 77 | :return: True if Test Run exists AND is open 78 | """ 79 | try: 80 | response = self.send_get(API_GET_RUN_URL.format(run_id=testrun_id)) 81 | return response['is_completed'] is False 82 | except testrail.APIError as error: 83 | logging.error(error) 84 | return False 85 | 86 | def is_testplan_available(self, testplan_id): 87 | """ Ask if Test Plan is available in TestRail. 88 | 89 | :param testplan_id: Testrail ID of the Test Plan 90 | :return: True if Test Plan exists AND is open 91 | """ 92 | try: 93 | response = self.send_get(API_GET_PLAN_URL.format(plan_id=testplan_id)) 94 | return response['is_completed'] is False 95 | except testrail.APIError as error: 96 | logging.error(error) 97 | return False 98 | 99 | def get_available_testruns(self, testplan_id): 100 | """ Get the list of available Test Runs contained in a Test Plan 101 | 102 | :param testplan_id: Testrail ID of the Test Plan 103 | :return: List of available Test Runs associated to a Test Plan in TestRail. 104 | """ 105 | testruns_list = [] 106 | response = self.send_get(API_GET_PLAN_URL.format(plan_id=testplan_id)) 107 | for entry in response['entries']: 108 | for run in entry['runs']: 109 | if not run['is_completed']: 110 | testruns_list.append(run['id']) 111 | return testruns_list 112 | 113 | @staticmethod 114 | def extract_testcase_id(str_content): 115 | """ Extract testcase ID (TestRail) from the given string. 116 | 117 | :param str_content: String containing a testcase ID. 118 | :return: Testcase ID (int). `None` if not found. 119 | """ 120 | testcase_id = None 121 | 122 | # Manage multiple value but take only the first chunk 123 | list_content = str_content.split() 124 | if list_content: 125 | first_chunk = list_content[0] 126 | try: 127 | testcase_id_str = ''.join(char for char in first_chunk if char in string.digits) 128 | testcase_id = int(testcase_id_str) 129 | except (TypeError, ValueError) as error: 130 | logging.error(error) 131 | 132 | return testcase_id 133 | 134 | def get_tests(self, testrun_id): 135 | """ Return the list of tests containing in a Test Run. 136 | 137 | :param testrun_id: TestRail ID of the Test Run 138 | 139 | """ 140 | try: 141 | return self.send_get(API_GET_TESTS_URL.format(run_id=testrun_id)) 142 | except testrail.APIError as error: 143 | logging.error(error) 144 | --------------------------------------------------------------------------------