@@ -1826,14 +1826,21 @@ def test_onecmd_raw_str_quit(base_app):
1826
1826
assert out == ''
1827
1827
1828
1828
1829
- def test_existing_history_file (capsys , request ):
1829
+ @pytest .fixture (scope = "session" )
1830
+ def hist_file ():
1831
+ fd , filename = tempfile .mkstemp (prefix = 'hist_file' , suffix = '.txt' )
1832
+ os .close (fd )
1833
+ yield filename
1834
+ # teardown code
1835
+ try :
1836
+ os .remove (filename )
1837
+ except FileNotFoundError :
1838
+ pass
1839
+
1840
+ def test_existing_history_file (hist_file , capsys ):
1830
1841
import atexit
1831
1842
import readline
1832
1843
1833
- # Create path to a history file
1834
- test_dir = os .path .dirname (request .module .__file__ )
1835
- hist_file = os .path .join (test_dir , 'hist_file' )
1836
-
1837
1844
# Create the history file before making cmd2 app
1838
1845
with open (hist_file , 'w' ):
1839
1846
pass
@@ -1842,21 +1849,20 @@ def test_existing_history_file(capsys, request):
1842
1849
app = cmd2 .Cmd (persistent_history_file = hist_file )
1843
1850
out , err = capsys .readouterr ()
1844
1851
1852
+ # Make sure there were no errors
1853
+ assert err == ''
1854
+
1845
1855
# Unregister the call to write_history_file that cmd2 did
1846
1856
atexit .unregister (readline .write_history_file )
1847
1857
1848
- # Remove created history file and make sure there were no errors
1858
+ # Remove created history file
1849
1859
os .remove (hist_file )
1850
- assert err == ''
1851
1860
1852
- def test_new_history_file (capsys , request ):
1861
+
1862
+ def test_new_history_file (hist_file , capsys ):
1853
1863
import atexit
1854
1864
import readline
1855
1865
1856
- # Create path to a history file
1857
- test_dir = os .path .dirname (request .module .__file__ )
1858
- hist_file = os .path .join (test_dir , 'hist_file' )
1859
-
1860
1866
# Remove any existing history file
1861
1867
try :
1862
1868
os .remove (hist_file )
@@ -1867,12 +1873,14 @@ def test_new_history_file(capsys, request):
1867
1873
app = cmd2 .Cmd (persistent_history_file = hist_file )
1868
1874
out , err = capsys .readouterr ()
1869
1875
1876
+ # Make sure there were no errors
1877
+ assert err == ''
1878
+
1870
1879
# Unregister the call to write_history_file that cmd2 did
1871
1880
atexit .unregister (readline .write_history_file )
1872
1881
1873
- # Remove created history file and make sure there were no errors
1882
+ # Remove created history file
1874
1883
os .remove (hist_file )
1875
- assert err == ''
1876
1884
1877
1885
def test_bad_history_file_path (capsys , request ):
1878
1886
# Use a directory path as the history file
0 commit comments