File size: 804 Bytes
d916065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest

from nltk.corpus.reader import CorpusReader


@pytest.fixture(autouse=True)
def mock_plot(mocker):
    """Disable matplotlib plotting in test code"""

    try:
        import matplotlib.pyplot as plt

        mocker.patch.object(plt, "gca")
        mocker.patch.object(plt, "show")
    except ImportError:
        pass


@pytest.fixture(scope="module", autouse=True)
def teardown_loaded_corpora():
    """

    After each test session ends (either doctest or unit test),

    unload any loaded corpora

    """

    yield  # first, wait for the test to end

    import nltk.corpus

    for name in dir(nltk.corpus):
        obj = getattr(nltk.corpus, name, None)
        if isinstance(obj, CorpusReader) and hasattr(obj, "_unload"):
            obj._unload()