Skip to content

Commit

Permalink
feat: Switch from nosetest to pytest (apache#10177)
Browse files Browse the repository at this point in the history
* Switch from nosetest to pytest

Fix schedule tests

Collect pytest coverage

Move pytest config into pytest.ini

Move cov to the pytest.ini

* Append coverage for the 2nd run

* Add coverage to all commands

* Coverage only for tests

* Get coverage from 1 place

* Rename classes to be  pytest compatible

* Test coverage for examples and tests

* Max diff to -1

* Explain how to run pytest for the whole project

* Do not append code coverage for the main run

* Do not run coverage on examples

Co-authored-by: bogdan kyryliuk <[email protected]>
  • Loading branch information
bkyryliuk and bogdan-dbx authored Jun 29, 2020
1 parent 72fc581 commit 4e340c8
Show file tree
Hide file tree
Showing 71 changed files with 139 additions and 155 deletions.
21 changes: 21 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
[pytest]
addopts = -ra -q
testpaths =
tests
python_files = *_test.py test_*.py *_tests.py
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ flask-testing==0.8.0
ipdb==0.12
isort==4.3.21
mypy==0.770
nose==1.3.7
pytest==5.4.3
pytest-cov==2.10.0
parameterized==0.7.4
pip-tools==5.1.2
pre-commit==1.17.0
Expand Down
4 changes: 2 additions & 2 deletions scripts/python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ echo "Superset config module: $SUPERSET_CONFIG"

superset db upgrade
superset init
nosetests --stop tests/load_examples_test.py
nosetests --stop --exclude=load_examples_test tests
pytest --maxfail=1 tests/load_examples_test.py
pytest --maxfail=1 --cov=superset --ignore=load_examples_test tests/*
4 changes: 2 additions & 2 deletions scripts/tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function test_init() {
echo --------------------
echo Load examples
echo --------------------
nosetests tests/load_examples_test.py
pytest -s tests/load_examples_test.py
}


Expand Down Expand Up @@ -145,5 +145,5 @@ fi

if [ $RUN_TESTS -eq 1 ]
then
nosetests --exclude=load_examples_test "${TEST_MODULE}"
pytest -s --ignore=load_examples_test "${TEST_MODULE}"
fi
7 changes: 0 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ all_files = 1
[upload_sphinx]
upload-dir = docs/_build/html

[nosetests]
verbosity = 3
detailed-errors = 1
with-coverage = 1
nocapture = 1
cover-package = superset

[isort]
combine_as_imports = true
include_trailing_comma = true
Expand Down
4 changes: 3 additions & 1 deletion tests/access_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ def create_access_request(session, ds_type, ds_name, role_name, user_name):
return access_request


class RequestAccessTests(SupersetTestCase):
class TestRequestAccess(SupersetTestCase):
@classmethod
def setUpClass(cls):
with app.app_context():
cls.create_druid_test_objects()

security_manager.add_role("override_me")
security_manager.add_role(TEST_ROLE_1)
security_manager.add_role(TEST_ROLE_2)
Expand Down
2 changes: 1 addition & 1 deletion tests/base_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Model1Api(BaseSupersetModelRestApi):
appbuilder.add_api(Model1Api)


class BaseModelRestApiTests(SupersetTestCase):
class TestBaseModelRestApi(SupersetTestCase):
def test_default_missing_declaration_get(self):
"""
API: Test default missing declaration on get
Expand Down
4 changes: 1 addition & 3 deletions tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class SupersetTestCase(TestCase):
"postgresql": "public",
}

def __init__(self, *args, **kwargs):
super(SupersetTestCase, self).__init__(*args, **kwargs)
self.maxDiff = None
maxDiff = -1

def create_app(self):
return app
Expand Down
5 changes: 1 addition & 4 deletions tests/cache_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
from .base_tests import SupersetTestCase


class CacheTests(SupersetTestCase):
def __init__(self, *args, **kwargs):
super(CacheTests, self).__init__(*args, **kwargs)

class TestCache(SupersetTestCase):
def setUp(self):
cache.clear()

Expand Down
6 changes: 3 additions & 3 deletions tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
DROP_TABLE_SLEEP_TIME = 10


class UtilityFunctionTests(SupersetTestCase):
class TestUtilityFunction(SupersetTestCase):
# TODO(bkyryliuk): support more cases in CTA function.
def test_create_table_as(self):
q = ParsedQuery("SELECT * FROM outer_space;")
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_create_table_as(self):
)


class AppContextTests(SupersetTestCase):
class TestAppContext(SupersetTestCase):
def test_in_app_context(self):
@celery_app.task()
def my_task():
Expand All @@ -95,7 +95,7 @@ def my_task():
CTAS_SCHEMA_NAME = "sqllab_test_db"


class CeleryTestCase(SupersetTestCase):
class TestCelery(SupersetTestCase):
def get_query_by_name(self, sql):
session = db.session
query = session.query(Query).filter_by(sql=sql).first()
Expand Down
5 changes: 1 addition & 4 deletions tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@
CHART_DATA_URI = "api/v1/chart/data"


class ChartApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
resource_name = "chart"

def __init__(self, *args, **kwargs):
super(ChartApiTests, self).__init__(*args, **kwargs)

def insert_chart(
self,
slice_name: str,
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/schema_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def load_query_context(payload: Dict[str, Any]) -> Tuple[QueryContext, Dict[str,
return ChartDataQueryContextSchema().load(payload)


class SchemaTestCase(SupersetTestCase):
class TestSchema(SupersetTestCase):
def test_query_context_limit_and_offset(self):
self.login(username="admin")
table_name = "birth_names"
Expand Down
5 changes: 1 addition & 4 deletions tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def apply_dttm_defaults(table: SqlaTable, dttm_defaults: Dict[str, Any]):
dbcol.expression = dttm_column_defaults["expression"]


class ConfigTests(SupersetTestCase):
def __init__(self, *args, **kwargs):
super(ConfigTests, self).__init__(*args, **kwargs)

class TestConfig(SupersetTestCase):
def setUp(self) -> None:
self.login(username="admin")
self._test_db_id = get_or_create_db(
Expand Down
5 changes: 1 addition & 4 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@
logger = logging.getLogger(__name__)


class CoreTests(SupersetTestCase):
def __init__(self, *args, **kwargs):
super(CoreTests, self).__init__(*args, **kwargs)

class TestCore(SupersetTestCase):
def setUp(self):
db.session.query(Query).delete()
db.session.query(DatasourceAccessRequest).delete()
Expand Down
2 changes: 1 addition & 1 deletion tests/dashboard_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from .base_tests import SupersetTestCase


class DashboardTests(SupersetTestCase):
class TestDashboard(SupersetTestCase):
def get_mock_positions(self, dash):
positions = {"DASHBOARD_VERSION_KEY": "v2"}
for i, slc in enumerate(dash.slices):
Expand Down
5 changes: 1 addition & 4 deletions tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from tests.base_tests import SupersetTestCase


class DashboardApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
resource_name = "dashboard"

dashboard_data = {
Expand All @@ -44,9 +44,6 @@ class DashboardApiTests(SupersetTestCase, ApiOwnersTestCaseMixin):
"published": False,
}

def __init__(self, *args, **kwargs):
super(DashboardApiTests, self).__init__(*args, **kwargs)

def insert_dashboard(
self,
dashboard_title: str,
Expand Down
2 changes: 1 addition & 1 deletion tests/dashboards/dao_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from tests.base_tests import SupersetTestCase


class DashboardDAOTests(SupersetTestCase):
class TestDashboardDAO(SupersetTestCase):
def test_set_dash_metadata(self):
dash = db.session.query(Dashboard).filter_by(slug="world_health").first()
data = dash.data
Expand Down
2 changes: 1 addition & 1 deletion tests/database_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .base_tests import SupersetTestCase


class DatabaseApiTests(SupersetTestCase):
class TestDatabaseApi(SupersetTestCase):
def test_get_items(self):
"""
Database API: Test get items
Expand Down
2 changes: 1 addition & 1 deletion tests/dataframe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from .base_tests import SupersetTestCase


class SupersetDataFrameTestCase(SupersetTestCase):
class TestSupersetDataFrame(SupersetTestCase):
def test_df_to_records(self):
data = [("a1", "b1", "c1"), ("a2", "b2", "c2")]
cursor_descr = (("a", "string"), ("b", "string"), ("c", "string"))
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from tests.base_tests import SupersetTestCase


class DatasetApiTests(SupersetTestCase):
class TestDatasetApi(SupersetTestCase):
@staticmethod
def insert_dataset(
table_name: str, schema: str, owners: List[int], database: Database
Expand Down
5 changes: 1 addition & 4 deletions tests/datasource_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
from .fixtures.datasource import datasource_post


class DatasourceTests(SupersetTestCase):
def __init__(self, *args, **kwargs):
super(DatasourceTests, self).__init__(*args, **kwargs)

class TestDatasource(SupersetTestCase):
def test_external_metadata(self):
self.login(username="admin")
tbl = self.get_table_by_name("birth_names")
Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/athena_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from tests.test_app import app # isort:skip

from superset.db_engine_specs.athena import AthenaEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class AthenaTestCase(DbEngineSpecTestCase):
class TestAthenaDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/base_engine_spec_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from superset.db_engine_specs.base import BaseEngineSpec, builtin_time_grains
from superset.db_engine_specs.sqlite import SqliteEngineSpec
from superset.utils.core import get_example_database
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec

from ..fixtures.pyodbcRow import Row


class DbEngineSpecsTests(DbEngineSpecTestCase):
class TestDbEngineSpecs(TestDbEngineSpec):
def test_extract_limit_from_query(self, engine_spec_class=BaseEngineSpec):
q0 = "select * from table"
q1 = "select * from mytable limit 10"
Expand Down
2 changes: 1 addition & 1 deletion tests/db_engine_specs/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from tests.test_app import app # isort:skip


class DbEngineSpecTestCase(SupersetTestCase):
class TestDbEngineSpec(SupersetTestCase):
def sql_limit_regex(
self, sql, expected_sql, engine_spec_class=MySQLEngineSpec, limit=1000
):
Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/bigquery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

from superset.db_engine_specs.base import BaseEngineSpec
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class BigQueryTestCase(DbEngineSpecTestCase):
class TestBigQueryDbEngineSpec(TestDbEngineSpec):
def test_bigquery_sqla_column_label(self):
"""
DB Eng Specs (bigquery): Test column label
Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/clickhouse_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.
from superset.db_engine_specs.clickhouse import ClickHouseEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class ClickHouseTestCase(DbEngineSpecTestCase):
class TestClickHouseDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/drill_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.
from superset.db_engine_specs.drill import DrillEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class DrillTestCase(DbEngineSpecTestCase):
class TestDrillDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/druid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from sqlalchemy import column

from superset.db_engine_specs.druid import DruidEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class DruidTestCase(DbEngineSpecTestCase):
class TestDruidDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/elasticsearch_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.
from superset.db_engine_specs.elasticsearch import ElasticSearchEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class ElasticSearchTestCase(DbEngineSpecTestCase):
class TestElasticSearchDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/hive_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
from superset.db_engine_specs.hive import HiveEngineSpec
from superset.exceptions import SupersetException
from superset.sql_parse import Table
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class HiveTests(DbEngineSpecTestCase):
class TestHiveDbEngineSpec(TestDbEngineSpec):
def test_0_progress(self):
log = """
17/02/07 18:26:27 INFO log.PerfLogger: <PERFLOG method=compile from=org.apache.hadoop.hive.ql.Driver>
Expand Down
4 changes: 2 additions & 2 deletions tests/db_engine_specs/impala_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# specific language governing permissions and limitations
# under the License.
from superset.db_engine_specs.impala import ImpalaEngineSpec
from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
from tests.db_engine_specs.base_tests import TestDbEngineSpec


class ImpalaTestCase(DbEngineSpecTestCase):
class TestImpalaDbEngineSpec(TestDbEngineSpec):
def test_convert_dttm(self):
dttm = self.get_dttm()

Expand Down
Loading

0 comments on commit 4e340c8

Please sign in to comment.