conftest.py is a special pytest file where global setup can take
place. Use this to set INTERNAL_OSINFO_DB_DATA_DIR=../data, which
fixes directly invoking pytest

Signed-off-by: Cole Robinson <[email protected]>
---
 Makefile          |  2 +-
 tests/conftest.py | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 tests/conftest.py

diff --git a/Makefile b/Makefile
index 0000306..d66ff2a 100644
--- a/Makefile
+++ b/Makefile
@@ -125,7 +125,7 @@ unit-tests: $(DATA_FILES) $(SCHEMA_FILES)
        if [ $$? -eq 0 ] ; then \
          for file in tests/test_*.py; do \
            log_file=`echo $$file | $(SED) -e 's/\.py/.log/'`; \
-           INTERNAL_OSINFO_DB_DATA_DIR=data $(PYTHON) -m pytest -s $$file 
--log-level=info | $(TEE) $$log_file; \
+           $(PYTHON) -m pytest -s $$file --log-level=info | $(TEE) $$log_file; 
\
          done; \
        else \
          echo "unit-tests are not going to be executed as no $(PYTHON) has 
been found"; \
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..ecc0813
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,14 @@
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+import os
+
+
+def _setup_env():
+    key = "INTERNAL_OSINFO_DB_DATA_DIR"
+    if key not in os.environ:
+        os.environ[key] = os.path.realpath(os.path.join(
+            os.path.dirname(__file__), "..", "data"))
+
+
+_setup_env()
-- 
2.21.0

_______________________________________________
Libosinfo mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libosinfo

Reply via email to