#137 Make tox work without tox-docker
Closed 3 years ago by csomh. Opened 5 years ago by csomh.
taskotron/ csomh/resultsdb easy-tox  into  develop

file modified
+2 -2
@@ -55,7 +55,7 @@ 

  test: $(VENV)

  	set -e

  	source $(VENV)/bin/activate;

- 	TEST='true' NO_CAN_HAS_POSTGRES='sadly' py.test --cov-report=term-missing --cov $(MODULENAME);

+ 	TEST='true' py.test --cov-report=term-missing --cov $(MODULENAME);

  	deactivate

  

  .PHONY: test-ci
@@ -63,7 +63,7 @@ 

  test-ci: $(VENV)

  	set -e

  	source $(VENV)/bin/activate

- 	TEST='true' NO_CAN_HAS_POSTGRES='sadly' py.test --cov-report=xml --cov $(MODULENAME)

+ 	TEST='true' py.test --cov-report=xml --cov $(MODULENAME)

  	deactivate

  

  .PHONY: pylint

file modified
+5 -5
@@ -84,15 +84,15 @@ 

  

      $ tox

  

- Note, that in order for some of the tests to work properly, tox is configured to spin-up PostgreSQL in a docker container using the

- ``tox-docker`` plugin, which needs to be installed separately. The best option probably is::

+ Note, that in order for some of the tests to work properly, tox needs to

+ spin-up PostgreSQL in a docker container using the ``tox-docker`` plugin. This

+ needs to be installed separately. The best option probably is::

  

      $ pip install --user tox-docker

      $ pip3 install --user tox-docker

  

- Should you, for some reason avoid docker, you could run the following command (with virtualenv active)::

- 

-     $ NO_CAN_HAS_POSTGRES=sadly pytest

+ If `tox-docker` is not present, the tests which require PostgreSQL, are

+ skipped.

  

  ## Deployment

  

file modified
+1 -1
@@ -37,7 +37,7 @@ 

  %setup -q

  

  %check

- NO_CAN_HAS_POSTGRES='sadly' PYTHONPATH=%{buildroot}%{python3_sitelib}/ pytest-3

+ PYTHONPATH=%{buildroot}%{python3_sitelib}/ pytest-3

  

  # This seems to be the only place where we can remove pyco files, see:

  # https://fedoraproject.org/wiki/Packaging:Python#Byte_compiling

file modified
+17 -31
@@ -23,6 +23,7 @@ 

  import tempfile

  import copy

  import time

+ import pytest

  

  import resultsdb

  import resultsdb.cli
@@ -863,13 +864,10 @@ 

          assert data['data'][1]['testcase']['name'] == self.ref_testcase_name

          assert data['data'][1]['outcome'] == "FAILED"

  

+     @pytest.mark.skipif(not os.getenv('POSTGRES_5432_TCP'),

+                         reason="Requires PostgreSQL, because DISTINCT ON works differently in SQLite")

      def test_get_results_latest_distinct_on(self):

          """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""

-         if os.getenv('NO_CAN_HAS_POSTGRES', None):

-             return

-         if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):

-             raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")

- 

          self.helper_create_testcase()

  

          self.helper_create_result(outcome="PASSED", data={'scenario': 'scenario1'}, testcase=self.ref_testcase_name)
@@ -886,21 +884,18 @@ 

          assert len(data['data']) == 1

          assert data['data'][0]['data']['scenario'][0] == 'scenario2'

  

+     @pytest.mark.skipif(not os.getenv('POSTGRES_5432_TCP'),

+                         reason="Requires PostgreSQL, because DISTINCT ON works differently in SQLite")

      def test_get_results_latest_distinct_on_more_specific_cases_1(self):

-         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""

-         if os.getenv('NO_CAN_HAS_POSTGRES', None):

-             return

-         if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):

-             raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")

+         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite

  

-         '''

              | id | testcase | scenario |

              |----|----------|----------|

              | 1  | tc_1     | s_1      |

              | 2  | tc_2     | s_1      |

              | 3  | tc_2     | s_2      |

              | 4  | tc_3     |          |

-         '''

+         """

          self.helper_create_result(outcome="PASSED", testcase='tc_1', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_2'})
@@ -911,14 +906,11 @@ 

  

          assert len(data['data']) == 4

  

+     @pytest.mark.skipif(not os.getenv('POSTGRES_5432_TCP'),

+                         reason="Requires PostgreSQL, because DISTINCT ON works differently in SQLite")

      def test_get_results_latest_distinct_on_more_specific_cases_2(self):

-         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""

-         if os.getenv('NO_CAN_HAS_POSTGRES', None):

-             return

-         if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):

-             raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")

+         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite

  

-         '''

              | id | testcase | scenario |

              |----|----------|----------|

              | 1  | tc_1     | s_1      |
@@ -926,7 +918,7 @@ 

              | 3  | tc_2     | s_2      |

              | 4  | tc_3     |          |

              | 5  | tc_1     |          |

-         '''

+         """

          self.helper_create_result(outcome="PASSED", testcase='tc_1', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_2'})
@@ -938,14 +930,11 @@ 

  

          assert len(data['data']) == 5

  

+     @pytest.mark.skipif(not os.getenv('POSTGRES_5432_TCP'),

+                         reason="Requires PostgreSQL, because DISTINCT ON works differently in SQLite")

      def test_get_results_latest_distinct_on_more_specific_cases_2(self):

-         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""

-         if os.getenv('NO_CAN_HAS_POSTGRES', None):

-             return

-         if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):

-             raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")

+         """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite

  

-         '''

              | id | testcase | scenario |

              |----|----------|----------|

              | 1  | tc_1     | s_1      |
@@ -954,7 +943,7 @@ 

              | 4  | tc_3     |          |

              | 5  | tc_1     |          |

              | 6  | tc_1     | s_1      |

-         '''

+         """

          self.helper_create_result(outcome="PASSED", testcase='tc_1', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_1'})

          self.helper_create_result(outcome="PASSED", testcase='tc_2', data={'item': 'grub', 'scenario': 's_2'})
@@ -971,13 +960,10 @@ 

          assert tc_1s[0]['outcome'] == 'INFO'

          assert tc_1s[1]['outcome'] == 'FAILED'

  

+     @pytest.mark.skipif(not os.getenv('POSTGRES_5432_TCP'),

+                         reason="Requires PostgreSQL, because DISTINCT ON works differently in SQLite")

      def test_get_results_latest_distinct_on_with_scenario_not_defined(self):

          """This test requires PostgreSQL, because DISTINCT ON does work differently in SQLite"""

-         if os.getenv('NO_CAN_HAS_POSTGRES', None):

-             return

-         if resultsdb.app.config['SQLALCHEMY_DATABASE_URI'].startswith('sqlite'):

-             raise Exception("This test requires PostgreSQL to work properly. You can disable it by setting NO_CAN_HAS_POSTGRES env variable to any non-empty value")

- 

          self.helper_create_testcase()

          self.helper_create_result(outcome="PASSED", testcase=self.ref_testcase_name)

          self.helper_create_result(outcome="FAILED", testcase=self.ref_testcase_name)

file modified
-2
@@ -18,7 +18,6 @@ 

  

  [tox]

  envlist = py27,py36,py37

- requires = tox-docker

  

  [testenv]

  docker = postgres:latest
@@ -35,4 +34,3 @@ 

  # tests read HOME

  passenv =

      HOME

-     NO_CAN_HAS_POSTGRES

This will make tox-docker optional for running the tests. In case
tox-docker is not installed, tox ignores the docker configuration for
the test environment.

When the above happens the POSTGRES_5432_TCP environment variable will
be missing. This can be used as a condition for pytest.mark.skipif to
skip the tests which need PostgreSQL running.

The above should improve developer experience.

Signed-off-by: Hunor Csomortáni csomh@redhat.com

Awesome! I got so worked up with that, trying to work around it, that this obvious path did not even cross my mind :)

Looks good "on paper", I'll give it a go once I have my laptop, and merge it then.

Thanks a lot!

@jskladan is this ok to be merged? :)

rebased onto 5980ae7

4 years ago

Rebased. @jskladan do you mind if I merge this?

Sure, looks OK to me. Thanks @csomh

Hm, I think this is not needed anymore. Closing.

Pull-Request has been closed by csomh

3 years ago