[TIP] gabbi now works with pytest..almost

chris.dent at gmail.com chris.dent at gmail.com
Thu Apr 7 02:45:16 PDT 2016


The latest release of gabbi, a testing library for HTTP APIs,
finally has support for running the tests it generates with pytest.

   https://pypi.python.org/pypi/gabbi

It works just fine when running all the tests in a suite but when
selecting just one test it doesn't execute a special and desirable
feature (described below). This isn't a deal breaker but if people
have ideas on how to make it work that would be very helpful.

In gabbi each HTTP request and response pair is wrapped as a single
test case. They are stated as an ordered list (in YAML). Each test
keep a reference to the previous test for two reasons:

* To be able to retrieve data from the headers and body of the
   previous response for use in the current request and response
   evaluation.

* To be able to select (by keyword or pattern matching) one test in
   the file and force its prior requests to run. This establishes
   each YAML file as an arc of work or interaction.

When pytest is provided a limit keyword (with -k) it will find the
correct test, see that the prior has not run and attemp to run it,
traversing to the start of the test stack. At that point it will run
that one test and exit and not traverse back down to the originally
requested test.

I'm not surprised that it doesn't work. The mechanism takes
advantage of some of the cruftiness of unittest to get its job done.
However it would be cool if I could.

Gabbi was originally writing with unittest and testrepository in
mind because that was expressed as an organizational requirement.
So its guts are very TestCase oriented, changing that now would be
challenging.

The pytest handling is simply a wrapper over the function that reads
in the yaml and builds unittest.TestSuites:

   https://github.com/cdent/gabbi/blob/e882f1df22ffa6f1e8239c831f738a85b447a044/gabbi/driver.py#L237-L258

In practice that call would be used like this:

   https://github.com/cdent/gabbi/blob/e882f1df22ffa6f1e8239c831f738a85b447a044/gabbi/tests/test_gabbits_pytest.py

If anyone has any ideas to explore, I'd love to hear them. Thanks.

-- 
Chris Dent                                   http://burningchrome.com/
                                 [...]



More information about the testing-in-python mailing list