The `when` will not be respected if `needs` is missing

For the following example:

build-a:
  stage: build
  script: sleep 60s
  only: [master]

build-b:
  stage: build
  script: sleep 1s && false

test-a:
  stage: test
  needs: [build-a]
  script: sleep 1s
  when: on_failure

test-b:
  stage: test
  script: sleep 1s

The test-a will be run, because build-b failed, even though we don't depend on build-b.

We should rather not run test-a at all in such cases.

Edited by Kamil Trzciński