GSOC Week 6 Review

Published: 07/12/2023

This week I am proud to have completed the conversion of the rest of the archiver test folder from unittest to pytest. If you will recall, two weeks ago I laid the foundation for these changes by removing the unittest based foundation `ArchiverTestBaseCase` - replacing the setup and teardown methods with pytest fixtures, and converting the rest of the methods to helper functions. My goal this week was to finish the conversion of the 38 test modules and remove all elements of unittest, replacing them with their pytest equivalents. By the end of the week I have completed the conversion of all files (over 6000 lines!) and submitted a PR for the changes that was able to pass all CI tests. Not only this, but the test suite runs slightly faster after my changes, and the code coverage has remained the same. 

This week went very smooth - I had a clear objective and with the foundation complete I was able to move quickly through the test files and to convert them. The challenge I hit this week was getting the tests to pass the CI checks, as I had only ran the tests on my local Mac machine. Windows tests ran into some errors that I was not seeing before, but I was able to do some trial and error that got them to work as intended. Additionally, I hit an issue with the socket path names for a test being too long when using the pytest fixture `tmp_dir`:
name = tmp_path / "unix-socket"

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

> sock.bind(os.path.join(name))

E OSError: AF_UNIX path too long


I switched to using tempfile.mktemp which allowed me to set a shorter path name. This passed the test locally, however when I pushed the changes to GitHub I received a warning: "Insecure temporary file. Call to deprecated function tempfile.mktemp may be insecure."  After doing some digging I found that mktemp files are fundamentally insecure, as they do not ensure exclusive access to a file with the temporary name they return. The file name returned by these functions is guaranteed to be unique on creation but the file must be opened in a separate operation. It was suggested to use a CM, tempfile.TemporaryDirectory, as a temporary directory. This directory was automatically cleaned up after exiting the CM, and worked as intended to pass the test and all CI checks.

The week ahead:
As I wrap up the Borg Unittest to Pytest conversion project, I still have a couple PR's left to get merged in. I will work with Thomas, my mentor who oversees Borg, to ensure that the PRs are buttoned up and ready to be merged. I will also prepare for my next project - increasing Vorta's code coverage - by reviewing the current code coverage, identifying areas of the code base that are lacking coverage, with a special focus on unit testing functions and methods as opposed to integration testing.