From 624f74d8b3e84d60e542766d60018510d3af248d Mon Sep 17 00:00:00 2001
From: Paul Wise <pabs3@bonedaddy.net>
Date: Sat, 26 Feb 2022 16:07:29 +0800
Subject: [PATCH 3/4] Only load data for train_gensim when it is being used by
 tests

Otherwise it will get loaded even when tests that use it aren't being run.
---
 gensim/test/test_fasttext.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gensim/test/test_fasttext.py b/gensim/test/test_fasttext.py
index ecc44a30..be831819 100644
--- a/gensim/test/test_fasttext.py
+++ b/gensim/test/test_fasttext.py
@@ -916,14 +916,18 @@ def test_sg_hs_training_fromfile(shrink_windows):
         assert overlap_count >= 2, message
 
 
-with open(datapath('toy-data.txt')) as fin:
-    TOY_SENTENCES = [fin.read().strip().split(' ')]
+TOY_SENTENCES = None
 
 
 def train_gensim(bucket=100, min_count=5):
     #
     # Set parameters to match those in the load_native function
     #
+    # Global toy data so there is one instance for all tests
+    global TOY_SENTENCES
+    if TOY_SENTENCES is None:
+        with open(datapath('toy-data.txt')) as fin:
+            TOY_SENTENCES = [fin.read().strip().split(' ')]
     model = FT_gensim(bucket=bucket, vector_size=5, alpha=0.05, workers=1, sample=0.0001, min_count=min_count)
     model.build_vocab(TOY_SENTENCES)
     model.train(TOY_SENTENCES, total_examples=len(TOY_SENTENCES), epochs=model.epochs)
-- 
2.36.0

