Skip to content

Commit

Permalink
test: make modular
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnasism committed Mar 16, 2024
1 parent 245edc2 commit 450f5b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .fixtures import * # noqa: F403
17 changes: 17 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

import pytest


@pytest.fixture
def temporary_file():
file_name = "test.txt"
yield file_name
os.remove(file_name)


@pytest.fixture
def temporary_async_file():
file_name = "test_async.txt"
yield file_name
os.remove(file_name)
16 changes: 8 additions & 8 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ async def write_to_file_async(file_name: str, body: str):
f.write(body)


def test_success_once():
write_to_file("test.txt", "hello world")
def test_success_once(temporary_file):
write_to_file(temporary_file, "hello world")
time.sleep(2)
with open("test.txt") as f:
assert "hello world" in f.readlines()
with open(temporary_file) as f:
assert "hello world" in f.read()


@pytest.mark.asyncio
async def test_success_once_async():
await write_to_file_async("test1.txt", "hello world")
async def test_success_once_async(temporary_async_file):
await write_to_file_async(temporary_async_file, "hello world")
time.sleep(2)
with open("test1.txt") as f:
assert "hello world" in f.readlines()
with open(temporary_async_file) as f:
assert "hello world" in f.read()

0 comments on commit 450f5b1

Please sign in to comment.