|
28 | 28 | HERE = os.path.dirname(__file__)
|
29 | 29 |
|
30 | 30 |
|
| 31 | +def pytest_generate_tests(metafunc): |
| 32 | + # Defers evaluation of the fixture until after collection. |
| 33 | + # https://docs.pytest.org/en/latest/example/parametrize.html\ |
| 34 | + # deferring-the-setup-of-parametrized-resources |
| 35 | + if 'html_file' in metafunc.fixturenames: |
| 36 | + paths = glob.glob( |
| 37 | + os.path.join(HERE, 'data', 'html_encoding', '*.html') |
| 38 | + ) |
| 39 | + metafunc.parametrize("html_file", paths, indirect=True) |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def html_file(request, datapath): |
| 44 | + return datapath(request.param) |
| 45 | + |
| 46 | + |
31 | 47 | def assert_framelist_equal(list1, list2, *args, **kwargs):
|
32 | 48 | assert len(list1) == len(list2), ('lists are not of equal size '
|
33 | 49 | 'len(list1) == {0}, '
|
@@ -838,22 +854,22 @@ def test_displayed_only(self, displayed_only, exp0, exp1):
|
838 | 854 | else:
|
839 | 855 | assert len(dfs) == 1 # Should not parse hidden table
|
840 | 856 |
|
841 |
| - @pytest.mark.parametrize("f", glob.glob( |
842 |
| - os.path.join(HERE, 'data', 'html_encoding', '*.html'))) |
843 |
| - def test_encode(self, f): |
844 |
| - _, encoding = os.path.splitext(os.path.basename(f))[0].split('_') |
| 857 | + def test_encode(self, html_file): |
| 858 | + _, encoding = os.path.splitext( |
| 859 | + os.path.basename(html_file) |
| 860 | + )[0].split('_') |
845 | 861 |
|
846 | 862 | try:
|
847 |
| - with open(f, 'rb') as fobj: |
| 863 | + with open(html_file, 'rb') as fobj: |
848 | 864 | from_string = self.read_html(fobj.read(), encoding=encoding,
|
849 | 865 | index_col=0).pop()
|
850 | 866 |
|
851 |
| - with open(f, 'rb') as fobj: |
| 867 | + with open(html_file, 'rb') as fobj: |
852 | 868 | from_file_like = self.read_html(BytesIO(fobj.read()),
|
853 | 869 | encoding=encoding,
|
854 | 870 | index_col=0).pop()
|
855 | 871 |
|
856 |
| - from_filename = self.read_html(f, encoding=encoding, |
| 872 | + from_filename = self.read_html(html_file, encoding=encoding, |
857 | 873 | index_col=0).pop()
|
858 | 874 | tm.assert_frame_equal(from_string, from_file_like)
|
859 | 875 | tm.assert_frame_equal(from_string, from_filename)
|
|
0 commit comments