Код: Выделить всё
import time
import pickle
class Solution:
""" A class that represents a solution of a very time-consuming problem. """
def solve_difficult_problem() -> Solution:
time.sleep(1)
return Solution()
def prepare_solution() -> None:
""" I solve the problem only once. I use the solution for all the
development of my new feature as it never changes. """
solution = solve_difficult_problem()
with open('solved.pickle', 'wb') as file:
pickle.dump(solution, file)
def my_feature(solution: Solution) -> None:
""" I am using the solution. """
print(solution)
def test_my_feature() -> None:
# prepare_solution() # I run it only once: at the first run.
with open('solved.pickle', 'rb') as file:
solution = pickle.load(file)
assert my_feature(solution) is None
Подробнее здесь: https://stackoverflow.com/questions/796 ... o-a-pickle