Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.26 KB

VDR309.md

File metadata and controls

39 lines (30 loc) · 1.26 KB

VDR309. Step should not have comparison without assert

It’s useless to compare anything in the assert step without asserting itself. This behavior is considered to be a careless mistake.

❌ Anti-pattern

class Scenario(vedro.Scenario):
    subject = "login as registered user"

    def given_user_data(self):
        self.user = fake(NewUserSchema)
    
    def given_registered_user(self):
        registered_user(self.user)    

    def when_user_logins(self):
        self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)

    def then_it_should_return_success_response(self):
        assert self.response.status_code == 200
        self.response.body == schema.dict({"assert_token": schema.str})

✅ Best practice

class Scenario(vedro.Scenario):
    subject = "login as registered user"

    def given_user_data(self):
        self.user = fake(NewUserSchema)
    
    def given_registered_user(self):
        registered_user(self.user)    

    def when_user_logins(self):
        self.response = httpx.post(f"{API_URL}/auth/login", json=self.user)

    def then_it_should_return_success_response(self):
        assert self.response.status_code == 200
        assert self.response.body == schema.dict({"assert_token": schema.str})