Skip to content

Commit

Permalink
test(ingest): use pytest-random-order for unit tests (#9753)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Feb 9, 2024
1 parent 93a7afb commit 24da7a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion metadata-ingestion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ task testQuick(type: Exec, dependsOn: [installDev, ':metadata-models:generateJso
outputs.dir("${venv_name}")
def cvg_arg = get_coverage_arg("quick")
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && pytest ${cvg_arg} tests/unit --durations=20 -m 'not integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
"source ${venv_name}/bin/activate && pytest ${cvg_arg} tests/unit --random-order --durations=20 -m 'not integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
}

task installDevTest(type: Exec, dependsOn: [install]) {
Expand Down
1 change: 1 addition & 0 deletions metadata-ingestion/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@
"pytest-asyncio>=0.16.0",
"pytest-cov>=2.8.1",
"pytest-docker>=1.1.0",
"pytest-random-order~=1.1.0",
deepdiff_dep,
"requests-mock",
"freezegun",
Expand Down
6 changes: 3 additions & 3 deletions metadata-ingestion/src/datahub/ingestion/source/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,19 @@ def _extract_record(
# TODO Add topic properties (Pulsar 2.10.0 feature)
# 3. Construct and emit dataset properties aspect
if schema is not None:
# Add some static properties to the schema properties
schema_properties = {
**schema.properties,
"schema_version": str(schema.schema_version),
"schema_type": schema.schema_type,
"partitioned": str(partitioned).lower(),
}
# Add some static properties to the schema properties
schema.properties.update(schema_properties)

yield MetadataChangeProposalWrapper(
entityUrn=dataset_urn,
aspect=DatasetPropertiesClass(
description=schema.schema_description,
customProperties=schema.properties,
customProperties=schema_properties,
),
).as_workunit()

Expand Down
24 changes: 11 additions & 13 deletions metadata-ingestion/tests/unit/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pathlib
from typing import Any, Iterable, List, Optional, cast
from typing import Iterable, List, cast
from unittest.mock import patch

import pytest
Expand All @@ -24,6 +24,10 @@

FROZEN_TIME = "2020-04-14 07:00:00"

# TODO: It seems like one of these tests writes to ~/.datahubenv or otherwise sets
# some global config, which impacts other tests.
pytestmark = pytest.mark.random_order(disabled=True)


class TestPipeline(object):
@patch("datahub.ingestion.source.kafka.KafkaSource.get_workunits", autospec=True)
Expand Down Expand Up @@ -59,22 +63,16 @@ def test_configure_without_sink(self, mock_emitter, mock_graph):
{
"source": {
"type": "file",
"config": {"filename": "test_file.json"},
"config": {"path": "test_file.json"},
},
}
)
# assert that the default sink config is for a DatahubRestSink
assert isinstance(pipeline.config.sink, DynamicTypedConfig)
assert pipeline.config.sink.type == "datahub-rest"
assert pipeline.config.sink.config == {
"server": "http://localhost:8080",
"token": Optional[Any],
# value is read from ~/datahubenv which may be None or not
} or pipeline.config.sink.config == {
"server": "http://localhost:8080",
"token": None,
# value is read from ~/datahubenv which may be None or not
}
assert isinstance(pipeline.config.sink.config, dict)
assert pipeline.config.sink.config["server"] == "http://localhost:8080"
# token value is read from ~/.datahubenv which may be None or not

@freeze_time(FROZEN_TIME)
@patch(
Expand All @@ -92,7 +90,7 @@ def test_configure_with_rest_sink_initializes_graph(
{
"source": {
"type": "file",
"config": {"filename": "test_events.json"},
"config": {"path": "test_events.json"},
},
"sink": {
"type": "datahub-rest",
Expand Down Expand Up @@ -130,7 +128,7 @@ def test_configure_with_rest_sink_with_additional_props_initializes_graph(
{
"source": {
"type": "file",
"config": {"filename": "test_events.json"},
"config": {"path": "test_events.json"},
},
"sink": {
"type": "datahub-rest",
Expand Down

0 comments on commit 24da7a5

Please sign in to comment.