Skip to main content

Utility for translating AzureDevOps Test Plans to Gherkin Feature file and Pytest-BDD runners

Project description

Summary

This package provides a utility that translates tests plans, suites and cases in Azure DevOps (ADO) into validated gherkin feature files, and then uses pytest-bdd generate to create the runners for those tests.

After that, it can validate that the test directory has all of the necessary fixtures to run pytest using pytest-bdd given/when/then fixture decorators.

It leverages ADO's notion of Shared Steps to reduce duplication when authoring the features and scenarios. This lets given/when/then clauses to be written once, and used many times.

It is capable of leveraging parameters on the test case (both "shared" and "non-shared") as Examples, creating a Scenario Outline instead of the standard Scenario.

Installation

This package is written only in python, and can be installed using:

$ pip install adotestplan-to-pytestbdd

Usage

from adotestplan_to_pytestbdd import ADOTestPlan
url = 'https://dev.azure.com/[ORGANIZATON_HERE]'
pat = '[PAT_HERE]'
project = '[PROJECT_HERE]'
out_dir='output'
tp = ADOTestPlan(organization_url=url, pat=pat, project=project, out_dir=out_dir)

The above example hasn't yet "done anything", and is equivalent to the following:

from adotestplan_to_pytestbdd import ADOTestPlan
tp = ADOTestPlan()
tp.url = 'https://dev.azure.com/[ORGANIZATON_HERE]'
tp.pat = '[PAT_HERE]'
tp.project = '[PROJECT_HERE]'
tp.out_dir='output'

Put differently - until one of the built-in methods is invoked, properties can be set via init or via property access.

To populate the internal memory structures from ADO:

tp.populate()

Next, to write feature files to disk from the populated:

tp.write_feature_files()

At this point, the ADO test plan has been synchronized to feature files on disk. Its possible that is a sufficient stopping point.

At this point begins the pytest-bdd integration.

First, use this method:

tp.write_pytestbdd_runners()

to create test_xyz.py files on disk corresponding to the feature files generated above. This is a wrapper around pytest-bdd generate (see ado_test_plan.py).

One reason this is seen as useful is that it avoids "checking in" boilerplate/generated code - the test methods created here are basically stubs, the majority of the test occurs in the given/when/then fixtures. With this approach, the test_xyz.py files can be just as ephemeral as the .feature files they are generated from - the one piece that is persistent/checked in is the fixtures where the actual test implementation occurs.

At this point, call:

tp.validate_pytestbdd_runners_against_feature_files()

This final call uses pytest utilities to collect all fixtures in the specified test directory, and compares those against the needed fixtures, determined during the populate() phase. It will print informative messages, and in the end raise an exception if some fixtures are not found.

Testing

Please see TESTING.md for notes on running the tests associated with this package. Note this refers to the unit test for validating the package itself, not the tests generated by running this package normally. That can be done after code generation via a normal call to pytest.

Possible Enhancements

  • Split the 2 basic pieces of functionality into a separate package (1 being ADO to feature file translation, 2 being feature file to fixture "pool" checking)
  • Use pytest --fixtures to collect available fixtures instead of raw searching through files. This is likely a more robust way of making sure fixtures aren't being missed. (this was looked into briefly, and it appears to be MUCH less performant than raw searching (on the order of 7s compared to 30ms), so this was tabled for now)
  • Document how "tags" can be used to filter test cases if one wanted to extend this utility for their own workflows.
  • A lot of the functionality in the tasks.py methods delete_test_work_items and generate_test_work_items may be revelant for "round tripping" this utility - going from .feature files into ADO, which has some utility in and of itself - for instance, migrating from a plain-text file approach to an ADO Test Plan backed approach.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adotestplan_to_pytestbdd-0.1.6.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

adotestplan_to_pytestbdd-0.1.6-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file adotestplan_to_pytestbdd-0.1.6.tar.gz.

File metadata

File hashes

Hashes for adotestplan_to_pytestbdd-0.1.6.tar.gz
Algorithm Hash digest
SHA256 781950d5ad2a2ded732c41c24f251f7dbc8da3aaa46f1fdb79ec1751425c7944
MD5 6d15a9a9ab68ba69b3762525d0a6c4e9
BLAKE2b-256 a7f7e893a43f3b2d49762d865bf0d0f7d1afd072948694c2c5095e39a28f6e90

See more details on using hashes here.

File details

Details for the file adotestplan_to_pytestbdd-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for adotestplan_to_pytestbdd-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bd1f99bae81cdf8c40d5f36068a2c690eebd65ce4394ffd17d07788d3e2c2d49
MD5 c2bf51e523a0d85bbf0d0a76744b0964
BLAKE2b-256 c5c0d5cf33275cb14937ca0c736c14d5159442567acdf285f35d8ef02449bfd9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page