vendredi 14 septembre 2018

How to unit test variable reassignment in Python

Main question: What is the most efficient way to unit test whether a class variable (self.file_path) was successfully reassigned by a method given the below class?

class FileHandler(object):
    def __init__(self, file_path):
        self.file_path = file_path     # /original/path/file.csv

    def reassign_path(new_path):
        self.file_path = new_path      # /new/path/file.csv
        self.run_long_operation(self.file_path)

I initially tried testing whether the self.file_path variable was different after running the reassign_path(), but that method takes a very long time to finish and dramatically slows down testing.

Secondary questions:Is there a way to simply check whether a method reassigns a class variable without running the entire method? Is there a better way to approach this?

Aucun commentaire:

Enregistrer un commentaire