1
@pytest.fixture
def settings():
    with open('../config.yaml') as yaml_stream:
        return yaml.load(stream=yaml_stream)    


@pytest.fixture
def viewers(settings):
    try:
        data = requests.get(settings['endpoints']['viewers']).json()
        return data[0]['viewers']
    except Exception:
        print('ERROR retrieving viewers')
        raise(SystemExit)


@pytest.fixture
def viewers_buffer_health(viewers):
    print(viewers)
    viewers_with_buffer_health = {}
    for viewer in viewers:
        try:
            data = requests.get(settings['endpoints']['node_buffer_health']).replace('<NODE_ID>', viewer)
        except Exception as e:
            print('ERROR retrieving buffer_health for {}'.format(viewer))
            raise(SystemExit)
        viewers_with_buffer_health[viewer] = data[0]['avg_buffer_health']
    return viewers_with_buffer_health

The fixture viewers_buffer_health is failing all the time on the requests because 'function' object is not subscriptable

Other times I have seen such error it has been because I was calling a variable and a function by the same name, but it's not the case (or I'm blind at all).

Although it shouldn't matter, the output of viewers is a list like ['a4a6b1c0-e98a-42c8-abe9-f4289360c220', '152bff1c-e82e-49e1-92b6-f652c58d3145', '55a06a01-9956-4d7c-bfd0-5a2e6a27b62b']

7
  • What is settings? Commented May 9, 2018 at 10:43
  • @IgnacioVazquez-Abrams just added it
    – user4093955
    Commented May 9, 2018 at 10:46
  • Okay, well, it's a function. You can't subscript that. Commented May 9, 2018 at 10:50
  • @IgnacioVazquez-Abrams it's a fixture, you can pass it to another fixture. For example, the fixture viewers uses settings as well, and it doesn't complain.
    – user4093955
    Commented May 9, 2018 at 10:53
  • 1
    Yeah you forgot the settings parameter in def viewers_buffer_health
    – Alex Hall
    Commented May 9, 2018 at 10:55

2 Answers 2

1

Since viewers_buffer_health() doesn't have a local definition for settings it is using the function defined previously. If it is meant to work in the same manner as viewers() then you will need to add a settings argument to its current set of arguments.

0

settings is a function.

data = requests.get(settings()['endpoints']['node_buffer_health']).replace('<NODE_ID>', viewer)