Please find the code below that I have added in environment.py file for after_scenario I do not get any error but neither are my tests marked with appropriate status on Browserstack
def after_scenario(context, scenario):
if scenario.status == Status.failed:
    requests.put(
        "http://Username:[email protected]/automate/sessions/iOS-Appium.json".format(
            context.driver.session_id),
        json={"status": "completed", "reason": "Test Failed"})
else:
    requests.put(
        "http://username:[email protected]/automate/sessions/iOS-Appium.json".format(
            context.driver.session_id),
        json={"status": "completed", "reason": "Test Pass"})
				
                        
The REST API for appium is as follows, changing the API call made fixed the issue