Skip to content

Commit f7b2d49

Browse files
authored
Merge pull request #1 from SyntaxAerror/gh-pytest
Create python-package.yml
2 parents 147dc53 + c2258bd commit f7b2d49

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python package
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.12", "3.13"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install flake8 pytest
31+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32+
- name: Lint with flake8
33+
run: |
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
36+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
37+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
38+
- name: Test with pytest
39+
run: |
40+
pytest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ celerybeat.pid
138138
.env
139139
.envrc
140140
.venv
141+
.venv_test
141142
env/
142143
venv/
143144
ENV/

tests/test_tools.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
ROOT = Path(__file__).resolve().parent.parent
1212
SCRIPT = ROOT / 'tools.sh'
1313
VENV_TEST = ROOT / '.venv_test'
14-
PACKAGE_NAME = 'stat_log_db'
14+
PACKAGE_NAME = 'stat-log-db'
15+
16+
GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true"
1517

1618
#endregion
1719

@@ -82,13 +84,15 @@ def test_help():
8284
except AssertionError:
8385
assert out.strip() == readme_content.strip(), "Help output does not match README content (leading & trailing whitespace stripped)"
8486

87+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
8588
def test_install_dev(test_venv):
8689
code, out = run_tools(['-id'], use_test_venv=True)
8790
assert code == 0
8891
assert 'Installing' in out
8992
assert 'dev' in out
9093
assert is_installed(PACKAGE_NAME), 'Package should be installed after dev install'
9194

95+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
9296
def test_install_normal(test_venv):
9397
code, out = run_tools(['-in'], use_test_venv=True)
9498
assert code == 0
@@ -102,6 +106,7 @@ def test_install_invalid_arg(test_venv):
102106
assert ('Unsupported argument' in out) or ('Invalid install mode' in out)
103107
assert not is_installed(PACKAGE_NAME), 'Package should not be installed after invalid install argument'
104108

109+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
105110
def test_uninstall(test_venv):
106111
# Ensure something installed first (dev mode)
107112
icode, iout = run_tools(['-id'], use_test_venv=True)
@@ -113,6 +118,7 @@ def test_uninstall(test_venv):
113118
assert 'Uninstall complete' in uout
114119
assert not is_installed(PACKAGE_NAME), 'Package should not be installed after uninstall'
115120

121+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
116122
def test_install_and_clean_multi_flag(test_venv):
117123
code, out = run_tools(['-id', '-c'], use_test_venv=True)
118124
assert code == 0
@@ -135,6 +141,7 @@ def test_test_invalid_arg():
135141
assert code == 1
136142
assert ('Unsupported argument' in out) or ('Invalid test mode' in out)
137143

144+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
138145
def test_clean():
139146
code, out = run_tools(['-c'])
140147
assert code == 0

0 commit comments

Comments
 (0)