Repository: hhursev/recipe-scrapers (language: python)

Issue:
Tests: use package metadata as source of README test data.
This works for me locally on Py3.11; I'm not 100% certain whether this is entirely backwards compatible through Py3.8.

May resolve #1160.


Discussion / hints:
@rmdluo @jknndy the `README.rst` file isn't included in the built `recipe_scrapers` Python library package -- however, the same metadata is available in the package `description`, and the `test_includes` unit test (the one that checks for all of the scraper hyperlinks) does work using that text instead.

What do you think about this as a potential change to read the content from the package metadata?
This should be a reversible decision, so I'm going to move ahead with it in order to resolve #1160.  If we later discover that we have to backtrack/revert, that's OK.

Fix patch:
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 1743c71d8..f395db404 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,3 +1,4 @@
 -e .
 coverage>=7.4.4
 types-beautifulsoup4>=4.12.0
+importlib-metadata>=4.6 ; python_version < "3.10"


Test patch:
diff --git a/tests/library/test_readme.py b/tests/library/test_readme.py
index 978bd6746..878838b0a 100644
--- a/tests/library/test_readme.py
+++ b/tests/library/test_readme.py
@@ -2,7 +2,15 @@
 import sys
 import unittest
 from collections import defaultdict
-from importlib.metadata import PackageNotFoundError, metadata
+
+if sys.version_info >= (3, 10):
+    from importlib.metadata import PackageNotFoundError, metadata
+else:
+    # TODO: Remove this branch once py3.10 is our minimum baseline;
+    # package description metadata (that we rely on for 'test_includes') is
+    # only available in importlib.metadata from py3.10 onwards
+    from importlib_metadata import PackageNotFoundError, metadata
+
 from typing import Dict, List, Optional, Tuple
 
 from recipe_scrapers import SCRAPERS, AbstractScraper
@@ -121,13 +129,6 @@ def test_includes(self):
         scraper_index = get_scraper_index()
         primary_domains = sorted(scraper_index.keys())
 
-        # TODO: Remove this skip-branch once py3.10 is our minimum baseline;
-        # package description metadata (that we rely on for this test) is only
-        # available in importlib.metadata from py3.10 onwards
-        if sys.version_info < (3, 10):
-            msg = "Python 3.10+ is required for importlib.metadata to read package 'description' metadata."
-            self.skipTest(msg)
-
         try:
             lines = get_list_lines()
         except PackageNotFoundError: