Skip to content

Commit

Permalink
Pants: Minor test refactor to support running under pants+pytest (#6253)
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd authored Sep 26, 2024
2 parents e02aec0 + ddc00ce commit 91dd119
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Added
* Continue introducing `pants <https://www.pantsbuild.org/docs>`_ to improve DX (Developer Experience)
working on StackStorm, improve our security posture, and improve CI reliability thanks in part
to pants' use of PEX lockfiles. This is not a user-facing addition.
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251
#6118 #6141 #6133 #6120 #6181 #6183 #6200 #6237 #6229 #6240 #6241 #6244 #6251 #6253
Contributed by @cognifloyd
* Build of ST2 EL9 packages #6153
Contributed by @amanda11
Expand Down
6 changes: 5 additions & 1 deletion contrib/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ python_requirements(
)

python_sources(
dependencies=[":metadata"],
dependencies=[
":metadata",
"./actions",
"./actions/send_mail:send_mail_resources",
],
)
5 changes: 3 additions & 2 deletions contrib/core/actions/send_mail/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell_source(
source="send_mail",
st2_shell_sources_and_resources(
name="send_mail",
sources=["send_mail"],
skip_shellcheck=True,
)
8 changes: 8 additions & 0 deletions st2common/tests/unit/services/test_packs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from st2tests.fixtures.packs.orquesta_tests.fixture import (
PACK_NAME as TEST_SOURCE_WORKFLOW_PACK,
)
import st2tests.config as tests_config

SOURCE_ACTION_WITH_PYTHON_SCRIPT_RUNNER = {
"description": "Action which injects a new trigger in the system.",
Expand Down Expand Up @@ -416,6 +417,8 @@ def test_exception_to_remove_resource_metadata_file(self, remove):
class CloneActionDBAndFilesTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()
action_files_path = os.path.join(TEST_DEST_PACK_PATH, "actions")
workflow_files_path = os.path.join(action_files_path, "workflows")
if not os.path.isdir(action_files_path):
Expand Down Expand Up @@ -588,6 +591,11 @@ def test_workflows_directory_created_if_does_not_exist(self):


class CloneActionFilesBackupTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
tests_config.parse_args()

@classmethod
def tearDownClass(cls):
action_files_path = os.path.join(TEST_DEST_PACK_PATH, "actions")
Expand Down
2 changes: 1 addition & 1 deletion st2common/tests/unit/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def tearDown(self):
@classmethod
def tearDownClass(cls):
# since tearDown discconnects, dropping the database in tearDownClass
# fails withotu establishing a new connection.
# fails without establishing a new connection.
cls._establish_connection_and_re_create_db()
super().tearDownClass()

Expand Down
12 changes: 6 additions & 6 deletions st2common/tests/unit/test_util_file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@

class FileSystemUtilsTestCase(unittest.TestCase):
def test_get_file_list(self):
# NB: Make sure to exclude BUILD files as pants will not include them in the sandbox,
# but the BUILD files will be present if you directly run the tests.
basic_excludes = ["*.pyc", "__pycache__", "*BUILD"]

# Standard exclude pattern
directory = os.path.join(ST2TESTS_DIR, "policies")
expected = [
"BUILD",
"mock_exception.py",
"concurrency.py",
"__init__.py",
"meta/BUILD",
"meta/mock_exception.yaml",
"meta/concurrency.yaml",
"meta/__init__.py",
]
result = get_file_list(
directory=directory, exclude_patterns=["*.pyc", "__pycache__"]
)
result = get_file_list(directory=directory, exclude_patterns=basic_excludes)
# directory listings are sorted because the item order must be exact for assert
# to validate equivalence. Directory item order doesn't matter in general and may
# even change on different platforms or locales.
Expand All @@ -55,7 +55,7 @@ def test_get_file_list(self):
"meta/__init__.py",
]
result = get_file_list(
directory=directory, exclude_patterns=["*.pyc", "*.yaml", "*BUILD"]
directory=directory, exclude_patterns=["*.yaml"] + basic_excludes
)
# directory listings are sorted because the item order must be exact for assert
# to validate equivalence. Directory item order doesn't matter in general and may
Expand Down
8 changes: 7 additions & 1 deletion st2tests/st2tests/policies/meta/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
resources(
sources=["*.yaml"],
sources=[
"*.yaml",
# pants ignores empty __init__.py files.
# However, the tests for st2common.util.file_system need it to be present,
# so we treat it as a resource instead of a python source file.
"__init__.py",
],
)

0 comments on commit 91dd119

Please sign in to comment.