@@ -146,6 +146,70 @@ def prerelease_deps(session, implementation):
146146 )
147147
148148
149+ # Only test upb and python implementation backends.
150+ # As of protobuf 4.x, the "ccp" implementation is not available in the PyPI package as per
151+ # https://github.com/protocolbuffers/protobuf/tree/main/python#implementation-backends
152+ @nox .session (python = PYTHON_VERSIONS [- 1 ])
153+ @nox .parametrize ("implementation" , ["python" , "upb" ])
154+ def core_deps_from_source (session , implementation ):
155+ """Run all tests with core dependencies installed from source
156+ rather than pulling the dependencies from PyPI.
157+ """
158+
159+ session .env ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" ] = implementation
160+
161+ # Install test environment dependencies
162+ session .install ("coverage" , "pytest" , "pytest-cov" , "pytz" )
163+
164+ # Install the package without dependencies
165+ session .install ("-e" , "." , "--no-deps" )
166+
167+ # TODO(https://github.com/googleapis/gapic-generator-python/issues/2357): `protobuf` should be
168+ # added to the list below so that it is installed from source, rather than PyPI
169+ # Note: If a dependency is added to the `core_dependencies_from_source` list,
170+ # the `prerel_deps` list in the `prerelease_deps` nox session should also be updated.
171+ core_dependencies_from_source = [
172+ "google-api-core @ git+https://github.com/googleapis/google-cloud-python#egg=google-api-core&subdirectory=packages/google-api-core" ,
173+ # dependency of google-api-core
174+ "googleapis-common-protos @ git+https://github.com/googleapis/google-cloud-python#egg=googleapis-common-protos&subdirectory=packages/googleapis-common-protos" ,
175+ ]
176+
177+ for dep in core_dependencies_from_source :
178+ session .install (dep , "--no-deps" , "--ignore-installed" )
179+ print (f"Installed { dep } " )
180+
181+ # TODO(https://github.com/googleapis/google-cloud-python/issues/15115): Install protobuf from source at HEAD
182+ session .install ("--pre" , "--upgrade" , "protobuf" )
183+
184+ # Print out the installed package versions
185+ session .run (
186+ "python" , "-c" , "import google.protobuf; print(google.protobuf.__version__)"
187+ )
188+ session .run (
189+ "python" , "-c" , "import google.api_core; print(google.api_core.__version__)"
190+ )
191+
192+ # TODO(https://github.com/googleapis/proto-plus-python/issues/403): re-enable `-W=error`
193+ # The warnings-as-errors flag `-W=error` was removed in
194+ # https://github.com/googleapis/proto-plus-python/pull/400.
195+ # It should be re-added once issue
196+ # https://github.com/protocolbuffers/protobuf/issues/15077 is fixed.
197+ session .run (
198+ "pytest" ,
199+ "--quiet" ,
200+ * (
201+ session .posargs # Coverage info when running individual tests is annoying.
202+ or [
203+ "--cov=proto" ,
204+ "--cov-config=.coveragerc" ,
205+ "--cov-report=term" ,
206+ "--cov-report=html" ,
207+ "tests" ,
208+ ]
209+ ),
210+ )
211+
212+
149213@nox .session (python = "3.10" )
150214def docs (session ):
151215 """Build the docs."""
0 commit comments