Skip to content

Commit c9e3972

Browse files
authored
Only parse configuration once per session (#247)
1 parent 478a0a4 commit c9e3972

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

conftest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_go_to_google(py):
1818
assert 'Google' in py.title()
1919
"""
2020

21+
import copy
2122
import json
2223
import logging
2324
import os
@@ -109,9 +110,9 @@ def test_run(project_root, request) -> str:
109110
return test_results_dir
110111

111112

112-
@pytest.fixture(scope="function")
113-
def py_config(project_root, request) -> PyleniumConfig:
114-
"""Initialize a PyleniumConfig for each test
113+
@pytest.fixture(scope="session")
114+
def _py_config(project_root, request) -> PyleniumConfig:
115+
"""Read the PyleniumConfig for the test session
115116
116117
1. This starts by deserializing the user-created pylenium.json from the Project Root.
117118
2. If that file is not found, then proceed with Pylenium Defaults.
@@ -169,6 +170,15 @@ def py_config(project_root, request) -> PyleniumConfig:
169170
return config
170171

171172

173+
@pytest.fixture(scope="function")
174+
def py_config(_py_config) -> PyleniumConfig:
175+
"""Get a fresh copy of the PyleniumConfig for each test
176+
177+
See _py_config for how the initial configuration is read.
178+
"""
179+
return copy.deepcopy(_py_config)
180+
181+
172182
@pytest.fixture(scope="function")
173183
def test_case(test_run, py_config, request) -> TestCase:
174184
"""Manages data pertaining to the currently running Test Function or Case.

pylenium/scripts/conftest.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def test_go_to_google(py):
1818
assert 'Google' in py.title()
1919
"""
2020

21+
import copy
2122
import json
2223
import logging
2324
import os
@@ -109,9 +110,9 @@ def test_run(project_root, request) -> str:
109110
return test_results_dir
110111

111112

112-
@pytest.fixture(scope="function")
113-
def py_config(project_root, request) -> PyleniumConfig:
114-
"""Initialize a PyleniumConfig for each test
113+
@pytest.fixture(scope="session")
114+
def _py_config(project_root, request) -> PyleniumConfig:
115+
"""Read the PyleniumConfig for the test session
115116
116117
1. This starts by deserializing the user-created pylenium.json from the Project Root.
117118
2. If that file is not found, then proceed with Pylenium Defaults.
@@ -169,6 +170,15 @@ def py_config(project_root, request) -> PyleniumConfig:
169170
return config
170171

171172

173+
@pytest.fixture(scope="function")
174+
def py_config(_py_config) -> PyleniumConfig:
175+
"""Get a fresh copy of the PyleniumConfig for each test
176+
177+
See _py_config for how the initial configuration is read.
178+
"""
179+
return copy.deepcopy(_py_config)
180+
181+
172182
@pytest.fixture(scope="function")
173183
def test_case(test_run, py_config, request) -> TestCase:
174184
"""Manages data pertaining to the currently running Test Function or Case.

0 commit comments

Comments
 (0)