Last active
December 9, 2022 09:51
-
-
Save skhomuti/46f38eae42172e7998e7ecc7ad25c663 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
class App: | |
def create(self): | |
pass | |
def cleanup(self): | |
pass | |
@pytest.fixture | |
def app(): | |
app_instance = App() | |
yield app_instance | |
app_instance.cleanup() | |
def test_app(app): | |
app.create() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_app(): | |
return 1 | |
def delete_app(app_id): | |
print("Deleted " + str(app_id)) | |
def test_app(request): | |
app_id = create_app() | |
request.addfinalizer(lambda: delete_app(app_id)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
def create_app(): | |
return 1 | |
def delete_app(app_id): | |
print("Deleted " + str(app_id)) | |
@pytest.fixture(autouse=True) | |
def app_cleanup(request): | |
yield | |
if hasattr(request.node, "app_id"): | |
delete_app(request.node.app_id) | |
def test_app(request): | |
app_id = create_app() | |
request.node.app_id = app_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment