summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Lorey <git@karllorey.com>2022-08-18 17:38:56 +0200
committerKarl Lorey <git@karllorey.com>2022-08-18 17:39:36 +0200
commit1887459468e37942218d4be3ac1187709cb883ab (patch)
tree60205ca2684b3b54ca0f785fe74861b7b717c907
parentc0b805843d5ca05ef579a3fbd4f2e5a524688a27 (diff)
Fix testing examples by only running them in specialized environment
-rw-r--r--examples/__init__.py0
-rw-r--r--requirements/examples.in3
-rw-r--r--requirements/examples.txt18
-rw-r--r--tests/test_examples.py8
-rw-r--r--tox.ini7
5 files changed, 35 insertions, 1 deletions
diff --git a/examples/__init__.py b/examples/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/examples/__init__.py
diff --git a/requirements/examples.in b/requirements/examples.in
new file mode 100644
index 0000000..b9be6c2
--- /dev/null
+++ b/requirements/examples.in
@@ -0,0 +1,3 @@
+-r tests.in
+
+requests
diff --git a/requirements/examples.txt b/requirements/examples.txt
new file mode 100644
index 0000000..98e4f7b
--- /dev/null
+++ b/requirements/examples.txt
@@ -0,0 +1,18 @@
+# SHA1:ab5b5f892d20891e1e5bdb101c7d374c3f2621be
+#
+# This file is autogenerated by pip-compile-multi
+# To update, run:
+#
+# pip-compile-multi
+#
+-r tests.txt
+certifi==2022.6.15
+ # via requests
+charset-normalizer==2.1.0
+ # via requests
+idna==3.3
+ # via requests
+requests==2.28.1
+ # via -r requirements/examples.in
+urllib3==1.26.11
+ # via requests
diff --git a/tests/test_examples.py b/tests/test_examples.py
index ea385aa..a510ada 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -1,10 +1,16 @@
-from examples.quotes_to_scrape import main as quotes_to_scrape_main
+import os
+import pytest
+PYTEST_SKIP_EXAMPLES = os.environ.get("PYTEST_SKIP_EXAMPLES", "1")
+
+
+@pytest.mark.skipif(PYTEST_SKIP_EXAMPLES == "1", reason=f'"{PYTEST_SKIP_EXAMPLES=}"')
def test_example_quotes_to_scrape():
"""
Test if the example quotes_to_scrape.py works
"""
+ from examples.quotes_to_scrape import main as quotes_to_scrape_main
assert quotes_to_scrape_main() == {
"name": "J.K. Rowling",
diff --git a/tox.ini b/tox.ini
index d8200d3..7c28b56 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,6 +3,7 @@ envlist =
py3{11,10,9},pypy3{9}
style
docs
+ examples
skip_missing_interpreters = true
[testenv]
@@ -18,3 +19,9 @@ commands = pre-commit run --all-files --show-diff-on-failure
[testenv:docs]
deps = sphinx
commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
+
+[testenv:examples]
+deps = -rrequirements/examples.txt
+commands = pytest tests/test_examples.py
+setenv =
+ PYTEST_SKIP_EXAMPLES = 0