test: strict positional parameter enforcement is ignored under pytest
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 92/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- python
- Domain
- testing-qa
Research direction
Start in tests/init.py, then run tests/test_discovery.py with pytest and the -k test_tests_should_be_run_with_strict_positional_enforcement filter. Verify that the strict positional-parameter test raises TypeError and passes, and that the broader pytest or nox test run remains green.
Written by the indexing model from the issue text.
Description
Environment details
- OS type and version: Linux (gLinux / Debian based)
- Python version:
3.13.12(also affects all supported Python versions3.10+) - pip version:
26.0.1 google-api-python-clientversion:2.197.0(at commit6e471c075039dfef24e28d11658e03d5c949c7c3)
Steps to reproduce
- Check out the
mainbranch ofgoogle-api-python-client. - Set up a clean virtual environment and install test dependencies (
pytest,mock,parameterized). - Run the strict positional parameters enforcement test directly using
pytest:pytest tests/test_discovery.py -k test_tests_should_be_run_with_strict_positional_enforcement
Code example
The bug lies in how strict argument enforcement is configured for the test suite in tests/__init__.py.
Historically, the enforcement was configured inside the nose-legacy setup_package() hook:
# tests/__init__.py
from googleapiclient import _helpers as util
def setup_package():
"""Run on testing package."""
util.positional_parameters_enforcement = "EXCEPTION"
Because modern test runs in this repository (including via nox sessions) run under pytest, the setup_package() package-level hook is ignored. As a result, the tests run in warning-only mode, causing strict parameter assertion tests to be bypassed and fail with an AssertionError instead of raising TypeError.
Since the repository has migrated to pytest, this legacy hook is dead code. We should configure the variable directly at the package module level and completely remove the unused setup_package hook:
# tests/__init__.py
from googleapiclient import _helpers as util
+util.positional_parameters_enforcement = "EXCEPTION"
-
-def setup_package():
- """Run on testing package."""
- util.positional_parameters_enforcement = "EXCEPTION"
Stack trace
When running the tests using pytest, the test fails with the following output:
=================================== FAILURES ===================================
_ DiscoveryErrors.test_tests_should_be_run_with_strict_positional_enforcement __
self = <tests.test_discovery.DiscoveryErrors testMethod=test_tests_should_be_run_with_strict_positional_enforcement>
def test_tests_should_be_run_with_strict_positional_enforcement(self):
try:
plus = build("plus", "v1", None, static_discovery=False)
> self.fail("should have raised a TypeError exception over missing http=.")
E AssertionError: should have raised a TypeError exception over missing http=.
tests/test_discovery.py:509: AssertionError
------------------------------ Captured log call -------------------------------
WARNING googleapiclient._helpers:_helpers.py:129 build() takes at most 2 positional arguments (3 given)
=========================== short test summary info ============================
FAILED tests/test_discovery.py::DiscoveryErrors::test_tests_should_be_run_with_strict_positional_enforcement
====================== 1 failed, 332 deselected in 1.65s =======================
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 2.6k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 15
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from googleapis/google-api-python-client
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 5/5 Over a week Newbie friendliness 1/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
samples type: docs
Difficulty 3/5 1-2 days Newbie friendliness 52/100
All issues in googleapis/google-api-python-client
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100