ScannerError: mapping values are not allowed here

pmneve picture pmneve · Mar 25, 2019 · Viewed 9.2k times · Source

Using Tavern and trying to run tavern-ci against this yaml:

test_name: tavern poc

  - name: list
    request:
      url: https://xxx.xxx.xxx.us/api/v3/institutions/
      method: GET
    response:
      status_code: 200
      headers:
        content-type: application/json
      save:
        body:
          content: content

Am getting E ScannerError: mapping values are not allowed here E in "/Users/xxx/xxx/xxx/test_poc.tavern.yaml", line 3, column 9

Have tried many of the solutions presented here (most of which are 'put a space after the colon') without joy.

Yamllint gives the same error...

Answer

Anthon picture Anthon · Mar 25, 2019

At the root of your YAML document you have a mapping with key test_name and as value the start of a plain scalar tavern .....

The parser expects a key, with the same indent as the first line, on the second line or a continuation of your plain scalar from the first line. The second line is empty, so it continues with the same expectations on the third line. There it finds an - which is further indented than the beginning of test_name, so it is not a key, but part of the plain scalar. Then it finds name also part of a the plain scalar started on the first line and then : (colon + space).

But that colon+space is not allowed in plain scalar, as that gives potential ambiguity with the start of another key-value pair.

The unlikely solution is that you put double quotes before tavern and at the end of the YAML document.

More likely you should include a key for which the structure starting with - name: list this is the value. E.g.:

test_name: tavern poc

stages:
  - name: list
    request:

(as from the second entry you get from googling "tavern yaml")