Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pytest temp directory

def test_something_else(tmp_path):
    #create a file "myfile" in "mydir" in temp directory
    f1 = tmp_path / "mydir/myfile"
    f1.parent.mkdir() #create a directory "mydir" in temp folder (which is the parent directory of "myfile"
    f1.touch() #create a file "myfile" in "mydir"


    #write to file as normal 
    f1.write_text("text to myfile")

    assert f1.read() == "text to myfile"
Comment

pytest using tempfile

@pytest.fixture
def my_filepath(self, tmpdir):
    return tmpdir.mkdir("sub").join("testCurrentTicketCount.txt")
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter maximise window 
Python :: append multiple values to 2d list python 
Python :: sns histplot 
Python :: python recursion factorial 
Python :: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. buildozer 
Python :: python assert is datetime 
Python :: numpy scale array 
Python :: python bisect 
Python :: python make 1d array from n-d array 
Python :: activate python virtual environment 
Python :: print(int()) 
Python :: Python Datetime Get year, month, hour, minute, and timestamp 
Python :: selenium do not open browser window 
Python :: global variables python 
Python :: how to print in double quotes in python 
Python :: extract outliers from boxplot 
Python :: new line print python 
Python :: similarity imdex in python 
Python :: python - extract the price from a string 
Python :: turtle 
Python :: Add Cog to bot in Discord.py 
Python :: pandas drop duplicates but keep most recent date 
Python :: python input for competitive programming 
Python :: django composite primary key 
Python :: download unsplash images python without api 
Python :: python milisegundos 
Python :: pairwise function python 
Python :: add horizontal line to plotly scatter 
Python :: python merge dict 
Python :: Set value of dataframe using condition 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =