Chaining tests and passing an object from one test to another

后端 未结 2 946
南笙
南笙 2021-02-02 00:34

I\'m trying to pass the result of one test to another in pytest - or more specifically, reuse an object created by the first test in the second test. This is how I currently do

2条回答
  •  北海茫月
    2021-02-02 00:53

    #Use return and then call it later so it'll look like: 
    
    def test_creation():
        object = create_object()
        assert object.status == 'created'
        return(object.id) #this doesn't show on stdout but it will hand it to what's calling it
    
    
    def test_update(id):
        object = test_creation
        object.id = id
        object.update()
        assert object.status == 'updated' # some more tests
    
    #If this is what youre thinking of there ya go
    

提交回复
热议问题