Skip to content

Commit afb3ea3

Browse files
committed
Use pre-commit in project
1 parent edcd48d commit afb3ea3

File tree

10 files changed

+213
-137
lines changed

10 files changed

+213
-137
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ __pycache__
44
.cache
55
.DS_Store
66
.tox
7+
.eggs
8+
.vscode/
79
build
810
dist

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
3+
- repo: https://github.com/psf/black
4+
rev: stable
5+
hooks:
6+
- id: black
7+
args: [--safe, --quiet]
8+
language_version: python3
9+
10+
- repo: https://gitlab.com/pycqa/flake8
11+
rev: 3.7.7
12+
hooks:
13+
- id: flake8
14+
exclude: docs
15+
language_version: python3

.travis.yml

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,53 @@
11
language: python
2-
python:
3-
- 2.7
4-
- 3.6
5-
- pypy
6-
- pypy3
7-
- nightly
8-
matrix:
2+
jobs:
93
include:
10-
- python: 2.7
11-
env: TOXENV=flake8
12-
- python: 3.6
13-
env: TOXENV=flake8
14-
install:
15-
- pip install tox-travis
16-
script:
17-
- tox
18-
deploy:
19-
provider: pypi
20-
user: davehunt
21-
password:
22-
secure: "aSevNdJQLPH1S1TNaI+uSFdiZ+dEQkkvmLym5eA8vjvo0fV4FEQfjZg8rW69hfYAGA4EFkE3hQUs5IQIm5ug+A3FsMDjom4nAhCthq8g/5hviT+V6wVzoVdxf0JhlpLtDFteFTOKj5Z9PC/xhJJ/2/JrzmEwUwopiNtSNBdVwRXCOvb6L3aIU5DmTtuWokpBNmv4H2cdjCxwLROSlKdfFr4urUwiOst/A5W1HvdxWhEkQL7fLx/sUOHobYjkoL32miTpSHUJNH1L0G8uciMdtXTBY3HQ/uRfWaDs3iJ7Iwtk2hEB1ukPZiXtBX0FjTJXd71a4BvvG1FSQgeQ4zW1Fzf8Xz5qg0Z1Z+7DTFzekhd1AfcwDlr2Vh7xD6FCBSjFyAIXQ0n36mtoEfHDM6RQMQSQZm4j+4EOdFf9kfWsTn9XGWCr47r3qe+6SUzGSvHcD6LeoZZ2ZJjSk37vdQ0y28yvZr5goBFwY11MMjMVqLSA4mWhhueBWA7il9ciwfJbb6RThBfnHYdT8l4NRztkXz6QaW4KCJNVr3aE3MwPLzfux9JUUml//JUjuhChLpEvrAM6CRliZSawKdE9E2o5QOISt7yiEVdaxohAcfTkj5X+WTS5QBYjT/8+iV6KWDjghm/FH13/WZlcqMfC7be+EgXvqv3ffUanX7jnpzdg1sQ="
23-
distributions: sdist bdist_wheel
24-
on:
25-
tags: true
26-
repo: pytest-dev/pytest-base-url
27-
python: 3.6
4+
- stage: Tests
5+
name: Linting
6+
python: 3.7
7+
dist: xenial
8+
sudo: required
9+
env: TOXENV=linting
10+
11+
-
12+
python: 2.7
13+
env: TOXENV=py27
14+
15+
-
16+
python: 3.6
17+
env: TOXENV=py36
18+
19+
-
20+
python: 3.7
21+
dist: xenial
22+
sudo: required
23+
env: TOXENV=py37
24+
25+
-
26+
python: pypy
27+
env: TOXENV=pypy
28+
29+
-
30+
python: pypy3
31+
env: TOXENV=pypy3
32+
33+
- stage: deploy
34+
python: 3.7
35+
dist: xenial
36+
sudo: required
37+
install: skip
38+
script: skip
39+
deploy:
40+
provider: pypi
41+
user: davehunt
42+
password:
43+
secure: "aSevNdJQLPH1S1TNaI+uSFdiZ+dEQkkvmLym5eA8vjvo0fV4FEQfjZg8rW69hfYAGA4EFkE3hQUs5IQIm5ug+A3FsMDjom4nAhCthq8g/5hviT+V6wVzoVdxf0JhlpLtDFteFTOKj5Z9PC/xhJJ/2/JrzmEwUwopiNtSNBdVwRXCOvb6L3aIU5DmTtuWokpBNmv4H2cdjCxwLROSlKdfFr4urUwiOst/A5W1HvdxWhEkQL7fLx/sUOHobYjkoL32miTpSHUJNH1L0G8uciMdtXTBY3HQ/uRfWaDs3iJ7Iwtk2hEB1ukPZiXtBX0FjTJXd71a4BvvG1FSQgeQ4zW1Fzf8Xz5qg0Z1Z+7DTFzekhd1AfcwDlr2Vh7xD6FCBSjFyAIXQ0n36mtoEfHDM6RQMQSQZm4j+4EOdFf9kfWsTn9XGWCr47r3qe+6SUzGSvHcD6LeoZZ2ZJjSk37vdQ0y28yvZr5goBFwY11MMjMVqLSA4mWhhueBWA7il9ciwfJbb6RThBfnHYdT8l4NRztkXz6QaW4KCJNVr3aE3MwPLzfux9JUUml//JUjuhChLpEvrAM6CRliZSawKdE9E2o5QOISt7yiEVdaxohAcfTkj5X+WTS5QBYjT/8+iV6KWDjghm/FH13/WZlcqMfC7be+EgXvqv3ffUanX7jnpzdg1sQ="
44+
distributions: sdist bdist_wheel
45+
on:
46+
tags: true
47+
repo: pytest-dev/pytest-base-url
48+
49+
cache: pip
50+
51+
install: pip install tox
52+
53+
script: tox

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
tox = "*"
9+
flake8 = "*"
10+
black = "*"
11+
pre-commit = "*"
12+
13+
[packages]
14+
pytest-base-url = {editable = true,path = "."}

pytest_base_url/plugin.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,53 @@
1010
from requests.adapters import HTTPAdapter
1111

1212

13-
@pytest.fixture(scope='session')
13+
@pytest.fixture(scope="session")
1414
def base_url(request):
1515
"""Return a base URL"""
1616
config = request.config
17-
base_url = config.getoption('base_url')
17+
base_url = config.getoption("base_url")
1818
if base_url is not None:
1919
return base_url
2020

2121

22-
@pytest.fixture(scope='session', autouse=True)
22+
@pytest.fixture(scope="session", autouse=True)
2323
def _verify_url(request, base_url):
2424
"""Verifies the base URL"""
2525
verify = request.config.option.verify_base_url
2626
if base_url and verify:
2727
session = requests.Session()
28-
retries = Retry(backoff_factor=0.1,
29-
status_forcelist=[500, 502, 503, 504])
28+
retries = Retry(backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
3029
session.mount(base_url, HTTPAdapter(max_retries=retries))
3130
session.get(base_url)
3231

3332

3433
def pytest_configure(config):
35-
if hasattr(config, 'slaveinput'):
34+
if hasattr(config, "slaveinput"):
3635
return # xdist slave
37-
base_url = config.getoption('base_url') or config.getini('base_url')
36+
base_url = config.getoption("base_url") or config.getini("base_url")
3837
if base_url is not None:
3938
config.option.base_url = base_url
40-
if hasattr(config, '_metadata'):
41-
config._metadata['Base URL'] = base_url
39+
if hasattr(config, "_metadata"):
40+
config._metadata["Base URL"] = base_url
4241

4342

4443
def pytest_report_header(config, startdir):
45-
base_url = config.getoption('base_url')
44+
base_url = config.getoption("base_url")
4645
if base_url:
47-
return 'baseurl: {0}'.format(base_url)
46+
return "baseurl: {0}".format(base_url)
4847

4948

5049
def pytest_addoption(parser):
51-
parser.addini('base_url', help='base url for the application under test.')
50+
parser.addini("base_url", help="base url for the application under test.")
5251
parser.addoption(
53-
'--base-url',
54-
metavar='url',
55-
default=os.getenv('PYTEST_BASE_URL', None),
56-
help='base url for the application under test.')
52+
"--base-url",
53+
metavar="url",
54+
default=os.getenv("PYTEST_BASE_URL", None),
55+
help="base url for the application under test.",
56+
)
5757
parser.addoption(
58-
'--verify-base-url',
59-
action='store_true',
60-
default=not os.getenv('VERIFY_BASE_URL', 'false').lower() == 'false',
61-
help='verify the base url.')
58+
"--verify-base-url",
59+
action="store_true",
60+
default=not os.getenv("VERIFY_BASE_URL", "false").lower() == "false",
61+
help="verify the base url.",
62+
)

setup.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
from setuptools import setup
22

3-
setup(name='pytest-base-url',
4-
use_scm_version=True,
5-
description='pytest plugin for URL based testing',
6-
long_description=open('README.rst').read(),
7-
author='Dave Hunt',
8-
author_email='[email protected]',
9-
url='https://github.com/pytest-dev/pytest-base-url',
10-
packages=['pytest_base_url'],
11-
install_requires=[
12-
'pytest>=2.7.3',
13-
'requests>=2.9'],
14-
setup_requires=['setuptools_scm'],
15-
entry_points={'pytest11': ['base_url = pytest_base_url.plugin']},
16-
license='Mozilla Public License 2.0 (MPL 2.0)',
17-
keywords='py.test pytest base url mozilla automation',
18-
classifiers=[
19-
'Development Status :: 5 - Production/Stable',
20-
'Framework :: Pytest',
21-
'Intended Audience :: Developers',
22-
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
23-
'Operating System :: POSIX',
24-
'Operating System :: Microsoft :: Windows',
25-
'Operating System :: MacOS :: MacOS X',
26-
'Topic :: Software Development :: Quality Assurance',
27-
'Topic :: Software Development :: Testing',
28-
'Topic :: Utilities',
29-
'Programming Language :: Python',
30-
'Programming Language :: Python :: 2.7',
31-
'Programming Language :: Python :: 3.6',
32-
'Programming Language :: Python :: Implementation :: CPython',
33-
'Programming Language :: Python :: Implementation :: PyPy'])
3+
setup(
4+
name="pytest-base-url",
5+
use_scm_version=True,
6+
description="pytest plugin for URL based testing",
7+
long_description=open("README.rst").read(),
8+
author="Dave Hunt",
9+
author_email="[email protected]",
10+
url="https://github.com/pytest-dev/pytest-base-url",
11+
packages=["pytest_base_url"],
12+
install_requires=["pytest>=2.7.3", "requests>=2.9"],
13+
setup_requires=["setuptools_scm"],
14+
entry_points={"pytest11": ["base_url = pytest_base_url.plugin"]},
15+
license="Mozilla Public License 2.0 (MPL 2.0)",
16+
keywords="py.test pytest base url mozilla automation",
17+
classifiers=[
18+
"Development Status :: 5 - Production/Stable",
19+
"Framework :: Pytest",
20+
"Intended Audience :: Developers",
21+
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
22+
"Operating System :: POSIX",
23+
"Operating System :: Microsoft :: Windows",
24+
"Operating System :: MacOS :: MacOS X",
25+
"Topic :: Software Development :: Quality Assurance",
26+
"Topic :: Software Development :: Testing",
27+
"Topic :: Utilities",
28+
"Programming Language :: Python",
29+
"Programming Language :: Python :: 2.7",
30+
"Programming Language :: Python :: 3.6",
31+
"Programming Language :: Python :: Implementation :: CPython",
32+
"Programming Language :: Python :: Implementation :: PyPy",
33+
],
34+
)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

5-
pytest_plugins = 'pytester'
5+
pytest_plugins = "pytester"

tests/test_base_url.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,81 @@
44

55

66
def test_fixture(testdir):
7-
testdir.makepyfile("""
7+
testdir.makepyfile(
8+
"""
89
import pytest
910
@pytest.fixture(scope='session')
1011
def base_url():
1112
return 'foo'
1213
def test_fixture(base_url):
1314
assert base_url == 'foo'
14-
""")
15+
"""
16+
)
1517
result = testdir.runpytest()
1618
assert result.ret == 0
1719

1820

1921
def test_cli(testdir):
20-
testdir.makepyfile("""
22+
testdir.makepyfile(
23+
"""
2124
def test_funcarg(base_url):
2225
assert base_url == 'foo'
23-
""")
24-
result = testdir.runpytest('--base-url', 'foo')
26+
"""
27+
)
28+
result = testdir.runpytest("--base-url", "foo")
2529
assert result.ret == 0
2630

2731

2832
def test_config(testdir):
29-
testdir.makefile('.ini', pytest="""
33+
testdir.makefile(
34+
".ini",
35+
pytest="""
3036
[pytest]
3137
base_url=foo
32-
""")
33-
testdir.makepyfile("""
38+
""",
39+
)
40+
testdir.makepyfile(
41+
"""
3442
def test_config(request, base_url):
3543
assert request.config.getvalue('base_url') == 'foo'
3644
assert request.config.getini('base_url') == 'foo'
3745
assert base_url == 'foo'
38-
""")
46+
"""
47+
)
3948
result = testdir.runpytest()
4049
assert result.ret == 0
4150

4251

4352
def test_skip_config(testdir):
44-
testdir.makefile('.ini', pytest="""
53+
testdir.makefile(
54+
".ini",
55+
pytest="""
4556
[pytest]
4657
base_url=foo
47-
""")
48-
testdir.makepyfile("""
58+
""",
59+
)
60+
testdir.makepyfile(
61+
"""
4962
import pytest
5063
@pytest.mark.skipif(
51-
pytest.config.getoption('base_url') == 'foo',
64+
"config.getoption('base_url') == 'foo'",
5265
reason='skip')
5366
def test_skip_config(): pass
54-
""")
67+
"""
68+
)
5569
result = testdir.runpytest()
5670
assert result.ret == 0
5771

5872

5973
def test_env_var_set(testdir, monkeypatch):
60-
testdir.makepyfile("""
74+
testdir.makepyfile(
75+
"""
6176
def test_config(request, base_url):
6277
assert request.config.getvalue('base_url')
6378
assert base_url == 'yeehaw'
64-
""")
65-
monkeypatch.setenv('PYTEST_BASE_URL', 'yeehaw')
79+
"""
80+
)
81+
monkeypatch.setenv("PYTEST_BASE_URL", "yeehaw")
6682
reprec = testdir.inline_run()
6783
passed, skipped, failed = reprec.listoutcomes()
6884
assert len(passed) == 1

0 commit comments

Comments
 (0)