Skip to content

Commit c7b5885

Browse files
Merge pull request #387 from smokestacklightnin/ci/testing/add-pytest
Add testing with PyTest and GitHub Actions workflow
2 parents 03c5d69 + af4382a commit c7b5885

File tree

12 files changed

+95
-23
lines changed

12 files changed

+95
-23
lines changed

.github/actions/setup-env/action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Set up environment
2+
description: Set up environment and install package
3+
4+
inputs:
5+
python-version:
6+
default: "3.10"
7+
required: true
8+
package-root-dir:
9+
default: "./"
10+
required: true
11+
12+
runs:
13+
using: composite
14+
15+
steps:
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ inputs.python-version }}
20+
cache-dependency-path: |
21+
${{ inputs.package-root-dir }}/setup.py
22+
23+
- name: Install dependencies
24+
shell: bash
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install ${{ inputs.package-root-dir }}[test]
28+

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
on:
3+
push:
4+
paths-ignore:
5+
- '**.md'
6+
- 'docs/**'
7+
pull_request:
8+
branches: [ master ]
9+
paths-ignore:
10+
- '**.md'
11+
- 'docs/**'
12+
workflow_dispatch:
13+
14+
jobs:
15+
tests:
16+
if: github.actor != 'copybara-service[bot]'
17+
runs-on: ubuntu-latest
18+
19+
strategy:
20+
matrix:
21+
python-version: ['3.9', '3.10']
22+
package-root-dir: ['./', './tensorboard_plugin']
23+
24+
steps:
25+
- name: Checkout repo
26+
uses: actions/checkout@v4
27+
28+
- name: Set up environment
29+
uses: ./.github/actions/setup-env
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
package-root-dir: ${{ matrix.package-root-dir }}
33+
34+
- name: Run tests
35+
shell: bash
36+
run: |
37+
cd ${{ matrix.package-root-dir }}
38+
pytest

fairness_indicators/example_model_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,3 @@ def test_example_model(self):
163163
metric_values['fairness_indicators_metrics/true_negative_rate@0.1'],
164164
{'doubleValue': 1.0},
165165
)
166-
167-
168-
if __name__ == '__main__':
169-
tf.test.main()

fairness_indicators/remediation/weight_utils_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,3 @@ def test_create_difference_dictionary_bounded_metrics(self):
215215
self.assertIn('gender', res)
216216
self.assertAlmostEqual(res['gender']['female'], 0.125)
217217
self.assertAlmostEqual(res[''][''], 0)
218-
219-
220-
if __name__ == '__main__':
221-
tf.test.main()

fairness_indicators/tutorial_utils/util_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,3 @@ def test_get_eval_results_called_correclty(self, mock_run_model_analysis,
323323
eval_config=expected_eval_config,
324324
output_path=eval_results_path,
325325
extractors=None)
326-
327-
if __name__ == '__main__':
328-
tf.test.main()

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = "--import-mode=importlib"
3+
testpaths = "fairness_indicators"
4+
python_files = "*_test.py"

setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def select_constraint(default, nightly=None, git_master=None):
4343
'witwidget>=1.4.4,<2',
4444
'protobuf>=4.21.6,<6.0.0',
4545
]
46+
47+
TEST_PACKAGES = [
48+
'pytest>=8.3.0,<9',
49+
]
4650
# Get version from version module.
4751
with open('fairness_indicators/version.py') as fp:
4852
globals_dict = {}
@@ -66,6 +70,9 @@ def select_constraint(default, nightly=None, git_master=None):
6670
python_requires='>=3.9,<4',
6771
install_requires=REQUIRED_PACKAGES,
6872
tests_require=REQUIRED_PACKAGES,
73+
extras_require={
74+
'test': TEST_PACKAGES,
75+
},
6976
# PyPI package information.
7077
classifiers=[
7178
'Development Status :: 4 - Beta',

tensorboard_plugin/pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
addopts = "--import-mode=importlib"
3+
testpaths = "tensorboard_plugin_fairness_indicators"
4+
python_files = "*_test.py"

tensorboard_plugin/setup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def select_constraint(default, nightly=None, git_master=None):
5050
'werkzeug<2',
5151
]
5252

53+
TEST_PACKAGES = [
54+
'pytest>=8.3.0,<9',
55+
]
56+
5357
with open('README.md', 'r', encoding='utf-8') as fh:
5458
long_description = fh.read()
5559

@@ -80,6 +84,9 @@ def select_constraint(default, nightly=None, git_master=None):
8084
python_requires='>=3.9,<4',
8185
install_requires=REQUIRED_PACKAGES,
8286
tests_require=REQUIRED_PACKAGES,
87+
extras_require={
88+
'test': TEST_PACKAGES,
89+
},
8390
classifiers=[
8491
'Development Status :: 4 - Beta',
8592
'Intended Audience :: Developers',

tensorboard_plugin/tensorboard_plugin_fairness_indicators/metadata_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,3 @@ def testCreateSummaryMetadata_withoutDescription(self):
3434
summary_metadata = metadata.CreateSummaryMetadata()
3535
self.assertEqual(metadata.PLUGIN_NAME,
3636
summary_metadata.plugin_data.plugin_name)
37-
38-
39-
if __name__ == '__main__':
40-
tf.test.main()

0 commit comments

Comments
 (0)