I discovered an issue when testing an openpyxl 2.5.1 application with setup.py and py.test.
It occurs when using Python 2.7.14.
It does not occur on Python 3.6.3.
I haven't tried other Python versions.
PFA the minimum setup necessary to reproduce the bug.
Let me know if I should provide any other information to fix this bug.
To reproduce the issue, I created a simple program which opens an XLSX file and saves it under a different name. Additionally, I created a test case using unittest.
I am executing the test as explained here:
python setup.py pytest running pytest running egg_info creating UNKNOWN.egg-info writing requirements to UNKNOWN.egg-info/requires.txt writing UNKNOWN.egg-info/PKG-INFO writing top-level names to UNKNOWN.egg-info/top_level.txt writing dependency_links to UNKNOWN.egg-info/dependency_links.txt writing manifest file 'UNKNOWN.egg-info/SOURCES.txt' reading manifest file 'UNKNOWN.egg-info/SOURCES.txt' writing manifest file 'UNKNOWN.egg-info/SOURCES.txt' running build_ext ============================================================ test session starts ============================================================= platform linux2 -- Python 2.7.14, pytest-3.2.1, py-1.4.34, pluggy-0.4.0 rootdir: /home/boggers/eclipse-workspace/openpyxl_write_only_atexit_issue, inifile: collected 1 item test_main.py . ========================================================== 1 passed in 0.18 seconds ========================================================== Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.7/dist-packages/openpyxl/worksheet/write_only.py", line 31, in _openpyxl_shutdown for path in ALL_TEMP_FILES: TypeError: 'NoneType' object is not iterable Error in sys.exitfunc: Traceback (most recent call last): File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/local/lib/python2.7/dist-packages/openpyxl/worksheet/write_only.py", line 31, in _openpyxl_shutdown for path in ALL_TEMP_FILES: TypeError: 'NoneType' object is not iterable
My Two Cents
For some reason, the global list ALL_TEMP_FILES is treated as None when running the _openpyxl_shutdown() method. If I simply add and if statement that returns if the list is None (see below), this issue does not occur any more. However, I am not sure about the consequences of this dumb if statement.
@atexit.register def _openpyxl_shutdown(): global ALL_TEMP_FILES if ALL_TEMP_FILES is None: return for path in ALL_TEMP_FILES: if os.path.exists(path): os.remove(path)
On a different note, I also found this open issue. Is it possible that they are related?