constants.py
import os
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
INPUT_PATH = os.path.join(BASE_PATH, 'input')
FILE_INPUT1_PATH = os.path.join(INPUT_PATH, 'input1.csv')
FILE_INPUT2_PATH = os.path.join(INPUT_PATH, 'input2.csv')
PROCESSED_PATH = os.path.join(BASE_PATH, 'processed')
FILE_PROC1_PATH = os.path.join(PROCESSED_PATH, 'processed1.pkl')
FILE_PROC2_PATH = os.path.join(PROCESSED_PATH, 'processed2.pkl')
structure dir:
root
|__ constant.py
|__ input
|__ input1.csv
|__ input2.csv
|__ process
|__ processed1.pkl
|__ processed2.pkl
data_handling.py
from constants import FILE_INPUT1_PATH, FILE_INPUT2_PATH, FILE_PROC1_PATH, FILE_PROC2_PATH
def foo(*args):
file = FILE_INPUT1_PATH
# Here it is doing staff
# Finally I write data into FILE_PROC1_PATH
def bar(*args):
file = FILE_INPUT2_PATH
# Here it is doing staff
# Finally I write data into FILE_PROC2_PATH
Currently I'm trying to use pytest and testing foo()
and bar()
but I don't know how to proceed due to input files and processed files are too big and test process musn't override processed files.
One approach is to change definition bar()
to bar(path)
and then call bar(FILE_INPUT2_PATH)
but that it isn't make sense in the code because bar
always needs to read FILE_INPUT2_PATH
and it is called in many places.
Unit test for foo() and bar() would test if the processed files were created or not because it depends on *args
.
So... question is how can I solve it? Does a pattern/good practice exists for this case? What should I change in my code?