Skip to content

Instantly share code, notes, and snippets.

@skhomuti
Last active December 9, 2022 09:51
Show Gist options
  • Save skhomuti/46f38eae42172e7998e7ecc7ad25c663 to your computer and use it in GitHub Desktop.
Save skhomuti/46f38eae42172e7998e7ecc7ad25c663 to your computer and use it in GitHub Desktop.
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()
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))
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