My use-case is:
- I have a set of python scripts in one folder named 'Source'.
- In another folder named 'Test Scripts', I have a set of dedicated test-case scripts (using PyTest) for each python script. I am able to run the test-cases.
- Both the folders have init python script.
Problem: Temporary files are getting created during test-case run. I tried using a fixture to resolve this issue. Particularly, I tried following this SO question, PyTest: Auto delete temporary directory created with tmpdir_factory But, it didn't help me achieve my objective.
Moreover, I was wondering as if I can give python dict as a command-line argument because scripts in source folder run through command with the dictionary as an argument. Currently, I pass this command,
python -m pytest Test Scripts / test_script.py
Code Snippet of one of the test-case:
import pytest
from script_name import class_name
import shutil
@pytest.fixture
def obj_creation():
my_obj = class_name(data = " { 'a': 'b','c': 'd'} ")
return [my_obj]
@pytest.fixture(scope='session')
def project_file(tmpdir_factory):
my_tmpdir = tmpdir_factory.mktemp("data")
yield my_tmpdir
shutil.rmtree(str(my_tmpdir))
def test_no_new_office_ID(project_file, obj_creation):
x = obj_creation[0].ofc_email()
assert not x
I don't find any web material which is complete (with all possible use-cases). Please help me with this.