1

I am using pytest-dependency to create dependency on tests. I want the dependent test to get return value from another test.

Example:

@pytest.mark.dependency()
def test_owner_create_book(app):
  response = app.post(...) 
  return response["data"]["id"]

@pytest.mark.dependency(depends=["test_owner_create_book"])
def test_owner_read_book(app):
  # I want to get the id from previous response here

How can I get the response from dependency?

Packages in use:

pytest = "^6.1.1"
pytest-dependency = "^0.5.1"
PaxPrz
  • 1,778
  • 1
  • 13
  • 29
  • 3
    You cannot directly get the test output from another test. The best you can do is to write it into a global variable and read it from there (provided you cannot refactor your tests in a way where this is not needed, which would be the best solution). Also, at least your example looks as if the first test is not really a test, but could be made a fixture. – MrBean Bremen Jan 11 '21 at 07:26

0 Answers0