From bd69862a0200eee369ddd44ab2a28e0066ca582d Mon Sep 17 00:00:00 2001
From: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
Date: Thu, 3 Mar 2022 14:34:53 +0100
Subject: [PATCH] test input: use explicit package declaration (#345)

---
 .github/workflows/ci.yml                              |  5 ++---
 tests/conftest.py                                     | 10 ++++++++++
 tests/generate.py                                     |  2 +-
 tests/grpc/test_grpclib_client.py                     |  4 ++--
 tests/grpc/thing_service.py                           |  2 +-
 tests/inputs/bool/bool.proto                          |  2 ++
 tests/inputs/bytes/bytes.proto                        |  2 ++
 tests/inputs/casing/casing.proto                      |  2 ++
 .../casing_message_field_uppercase.proto              |  2 ++
 tests/inputs/deprecated/deprecated.proto              |  2 ++
 tests/inputs/deprecated_field/deprecated_field.proto  |  2 ++
 tests/inputs/double/double.proto                      |  2 ++
 tests/inputs/empty_repeated/empty_repeated.proto      |  2 ++
 tests/inputs/enum/enum.proto                          |  2 ++
 tests/inputs/example/example.proto                    |  2 ++
 tests/inputs/example_service/test_example_service.py  |  2 +-
 .../field_name_identical_to_type.proto                |  2 ++
 tests/inputs/fixed/fixed.proto                        |  2 ++
 tests/inputs/float/float.proto                        |  2 ++
 .../google_impl_behavior_equivalence.proto            |  2 ++
 tests/inputs/googletypes/googletypes.proto            |  2 ++
 .../googletypes_response/googletypes_response.proto   |  2 ++
 .../googletypes_response_embedded.proto               |  2 ++
 .../googletypes_service_returns_empty.proto           |  2 ++
 .../googletypes_service_returns_googletype.proto      |  2 ++
 .../googletypes_struct/googletypes_struct.proto       |  2 ++
 .../inputs/googletypes_value/googletypes_value.proto  |  2 ++
 .../import_capitalized_package/capitalized.proto      |  2 +-
 tests/inputs/import_capitalized_package/test.proto    |  2 ++
 .../import_child_package_from_package/child.proto     |  2 +-
 .../import_child_package_from_package.proto           |  2 ++
 .../package_message.proto                             |  2 +-
 .../inputs/import_child_package_from_root/child.proto |  2 +-
 .../import_child_package_from_root.proto              |  2 ++
 .../import_circular_dependency.proto                  |  2 ++
 tests/inputs/import_circular_dependency/other.proto   |  2 +-
 tests/inputs/import_circular_dependency/root.proto    |  2 ++
 tests/inputs/import_cousin_package/cousin.proto       |  2 +-
 tests/inputs/import_cousin_package/test.proto         |  2 +-
 .../import_cousin_package_same_name/cousin.proto      |  2 +-
 .../inputs/import_cousin_package_same_name/test.proto |  2 +-
 .../import_packages_same_name.proto                   |  2 ++
 tests/inputs/import_packages_same_name/posts_v1.proto |  2 +-
 tests/inputs/import_packages_same_name/users_v1.proto |  2 +-
 .../import_parent_package_from_child.proto            |  2 +-
 .../parent_package_message.proto                      |  2 +-
 .../inputs/import_root_package_from_child/child.proto |  2 +-
 .../inputs/import_root_package_from_child/root.proto  |  2 ++
 .../import_root_sibling/import_root_sibling.proto     |  2 ++
 tests/inputs/import_root_sibling/sibling.proto        |  2 ++
 .../child_package_request_message.proto               |  2 +-
 .../import_service_input_message.proto                |  2 ++
 .../request_message.proto                             |  2 ++
 tests/inputs/int32/int32.proto                        |  2 ++
 tests/inputs/map/map.proto                            |  2 ++
 tests/inputs/mapmessage/mapmessage.proto              |  2 ++
 .../namespace_builtin_types.proto                     |  2 ++
 .../namespace_keywords/namespace_keywords.proto       |  2 ++
 tests/inputs/nested/nested.proto                      |  2 ++
 tests/inputs/nested2/nested2.proto                    |  2 ++
 tests/inputs/nested2/package.proto                    |  2 +-
 tests/inputs/nestedtwice/nestedtwice.proto            |  2 ++
 tests/inputs/oneof/oneof.proto                        |  2 ++
 .../oneof_default_value_serialization.proto           |  2 ++
 tests/inputs/oneof_empty/oneof_empty.proto            |  2 ++
 tests/inputs/oneof_enum/oneof_enum.proto              |  2 ++
 .../proto3_field_presence/proto3_field_presence.proto |  2 ++
 .../proto3_field_presence_oneof.proto                 |  2 ++
 tests/inputs/recursivemessage/recursivemessage.proto  |  2 ++
 tests/inputs/ref/ref.proto                            |  2 ++
 tests/inputs/repeated/repeated.proto                  |  2 ++
 .../repeated_duration_timestamp.proto                 |  2 ++
 tests/inputs/repeatedpacked/repeatedpacked.proto      |  2 ++
 tests/inputs/service_separate_packages/messages.proto |  2 +-
 tests/inputs/service_separate_packages/service.proto  |  2 +-
 tests/inputs/signed/signed.proto                      |  2 ++
 tests/test_features.py                                |  2 +-
 tests/test_inputs.py                                  | 11 +----------
 78 files changed, 141 insertions(+), 37 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 02f5ea9..120bfa8 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,6 +13,7 @@ jobs:
     name: ${{ matrix.os }} / ${{ matrix.python-version }}
     runs-on: ${{ matrix.os }}-latest
     strategy:
+      fail-fast: false
       matrix:
         os: [Ubuntu, MacOS, Windows]
         python-version: ['3.6.7', '3.7', '3.8', '3.9', '3.10']
@@ -56,9 +57,7 @@ jobs:
 
       - name: Install dependencies
         shell: bash
-        run: |
-          poetry run python -m pip install pip -U
-          poetry install
+        run: poetry install
 
       - name: Generate code from proto files
         shell: bash
diff --git a/tests/conftest.py b/tests/conftest.py
index 6ab4f03..c6b256d 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,3 +1,6 @@
+import copy
+import sys
+
 import pytest
 
 
@@ -10,3 +13,10 @@ def pytest_addoption(parser):
 @pytest.fixture(scope="session")
 def repeat(request):
     return request.config.getoption("repeat")
+
+
+@pytest.fixture
+def reset_sys_path():
+    original = copy.deepcopy(sys.path)
+    yield
+    sys.path = original
diff --git a/tests/generate.py b/tests/generate.py
index 1d7d3e9..8599804 100755
--- a/tests/generate.py
+++ b/tests/generate.py
@@ -78,7 +78,7 @@ async def generate_test_case_output(
     """
 
     test_case_output_path_reference = output_path_reference.joinpath(test_case_name)
-    test_case_output_path_betterproto = output_path_betterproto.joinpath(test_case_name)
+    test_case_output_path_betterproto = output_path_betterproto
 
     os.makedirs(test_case_output_path_reference, exist_ok=True)
     os.makedirs(test_case_output_path_betterproto, exist_ok=True)
diff --git a/tests/grpc/test_grpclib_client.py b/tests/grpc/test_grpclib_client.py
index dc13885..28ce56f 100644
--- a/tests/grpc/test_grpclib_client.py
+++ b/tests/grpc/test_grpclib_client.py
@@ -7,12 +7,12 @@ import grpclib.server
 import asyncio
 import sys

-from tests.output_betterproto.service.service import (
+from tests.output_betterproto.service import (
     DoThingRequest,
     DoThingResponse,
     GetThingRequest,
     TestStub as ThingServiceClient,
 )
 import grpclib
 import grpclib.metadata
 
diff --git a/tests/grpc/thing_service.py b/tests/grpc/thing_service.py
index ae05852..835d6f1 100644
--- a/tests/grpc/thing_service.py
+++ b/tests/grpc/thing_service.py
@@ -1,4 +1,4 @@
-from tests.output_betterproto.service.service import (
+from tests.output_betterproto.service import (
     DoThingResponse,
     DoThingRequest,
     GetThingRequest,
diff --git a/tests/inputs/bool/bool.proto b/tests/inputs/bool/bool.proto
index 237e7db..77836b8 100644
--- a/tests/inputs/bool/bool.proto
+++ b/tests/inputs/bool/bool.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package bool;
+
 message Test {
     bool value = 1;
 }
diff --git a/tests/inputs/bytes/bytes.proto b/tests/inputs/bytes/bytes.proto
index de677e3..9895468 100644
--- a/tests/inputs/bytes/bytes.proto
+++ b/tests/inputs/bytes/bytes.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package bytes;
+
 message Test {
     bytes data = 1;
 }
diff --git a/tests/inputs/casing/casing.proto b/tests/inputs/casing/casing.proto
index ca458b5..2023d93 100644
--- a/tests/inputs/casing/casing.proto
+++ b/tests/inputs/casing/casing.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package casing;
+
 enum my_enum {
   ZERO = 0;
   ONE = 1;
diff --git a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto
index 9964dfa..c6d42c3 100644
--- a/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto
+++ b/tests/inputs/casing_message_field_uppercase/casing_message_field_uppercase.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package casing_message_field_uppercase;
+
 message Test {
   int32 UPPERCASE = 1;
   int32 UPPERCASE_V2 = 2;
diff --git a/tests/inputs/deprecated/deprecated.proto b/tests/inputs/deprecated/deprecated.proto
index aa1f818..d7102d0 100644
--- a/tests/inputs/deprecated/deprecated.proto
+++ b/tests/inputs/deprecated/deprecated.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package deprecated;
+
 // Some documentation about the Test message.
 message Test {
     // Some documentation about the value.
diff --git a/tests/inputs/deprecated_field/deprecated_field.proto b/tests/inputs/deprecated_field/deprecated_field.proto
index 04de1a9..d303c8d 100644
--- a/tests/inputs/deprecated_field/deprecated_field.proto
+++ b/tests/inputs/deprecated_field/deprecated_field.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package deprecated_field;
+
 // Some documentation about the Test message.
 message Test {
     // Some documentation about the value.
diff --git a/tests/inputs/double/double.proto b/tests/inputs/double/double.proto
index 88525d9..66aea95 100644
--- a/tests/inputs/double/double.proto
+++ b/tests/inputs/double/double.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package double;
+
 message Test {
     double count = 1;
 }
diff --git a/tests/inputs/empty_repeated/empty_repeated.proto b/tests/inputs/empty_repeated/empty_repeated.proto
index 3be831a..f787301 100644
--- a/tests/inputs/empty_repeated/empty_repeated.proto
+++ b/tests/inputs/empty_repeated/empty_repeated.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package empty_repeated;
+
 message MessageA {
   repeated float values = 1;
 }
diff --git a/tests/inputs/enum/enum.proto b/tests/inputs/enum/enum.proto
index a2dfe43..97e12b4 100644
--- a/tests/inputs/enum/enum.proto
+++ b/tests/inputs/enum/enum.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package enum;
+
 // Tests that enums are correctly serialized and that it correctly handles skipped and out-of-order enum values
 message Test {
   Choice choice = 1;
diff --git a/tests/inputs/example/example.proto b/tests/inputs/example/example.proto
index 3111058..56bd364 100644
--- a/tests/inputs/example/example.proto
+++ b/tests/inputs/example/example.proto
@@ -39,6 +39,8 @@
 
 syntax = "proto2";
 
+package example;
+
 // package google.protobuf;
 
 option go_package = "google.golang.org/protobuf/types/descriptorpb";
diff --git a/tests/inputs/example_service/test_example_service.py b/tests/inputs/example_service/test_example_service.py
index a770ed5..49c58f6 100644
--- a/tests/inputs/example_service/test_example_service.py
+++ b/tests/inputs/example_service/test_example_service.py
@@ -2,8 +2,8 @@ from typing import AsyncIterable, AsyncIterator
 
 import pytest
 from grpclib.testing import ChannelFor

-from tests.output_betterproto.example_service.example_service import (
+from tests.output_betterproto.example_service import (
     TestBase,
     TestStub,
     ExampleRequest,
diff --git a/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto
index 50fd590..81a0fc4 100644
--- a/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto
+++ b/tests/inputs/field_name_identical_to_type/field_name_identical_to_type.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package field_name_identical_to_type;
+
 // Tests that messages may contain fields with names that are identical to their python types (PR #294)
 
 message Test {
diff --git a/tests/inputs/fixed/fixed.proto b/tests/inputs/fixed/fixed.proto
index 50dad84..0f0ffb4 100644
--- a/tests/inputs/fixed/fixed.proto
+++ b/tests/inputs/fixed/fixed.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package fixed;
+
 message Test {
   fixed32 foo = 1;
   sfixed32 bar = 2;
diff --git a/tests/inputs/float/float.proto b/tests/inputs/float/float.proto
index 79922af..fea12b3 100644
--- a/tests/inputs/float/float.proto
+++ b/tests/inputs/float/float.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package float;
+
 // Some documentation about the Test message.
 message Test {
     double positive = 1;
diff --git a/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto b/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto
index 31b6bd3..5357a7c 100644
--- a/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto
+++ b/tests/inputs/google_impl_behavior_equivalence/google_impl_behavior_equivalence.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package google_impl_behavior_equivalence;
+
 message Foo{
   int64 bar = 1;
 }
diff --git a/tests/inputs/googletypes/googletypes.proto b/tests/inputs/googletypes/googletypes.proto
index ba3db12..ef8cb4a 100644
--- a/tests/inputs/googletypes/googletypes.proto
+++ b/tests/inputs/googletypes/googletypes.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes;
+
 import "google/protobuf/duration.proto";
 import "google/protobuf/timestamp.proto";
 import "google/protobuf/wrappers.proto";
diff --git a/tests/inputs/googletypes_response/googletypes_response.proto b/tests/inputs/googletypes_response/googletypes_response.proto
index 9b0be5c..8917d1c 100644
--- a/tests/inputs/googletypes_response/googletypes_response.proto
+++ b/tests/inputs/googletypes_response/googletypes_response.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_response;
+
 import "google/protobuf/wrappers.proto";
 
 // Tests that wrapped values can be used directly as return values
diff --git a/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto b/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto
index 89ae4cc..47284e3 100644
--- a/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto
+++ b/tests/inputs/googletypes_response_embedded/googletypes_response_embedded.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_response_embedded;
+
 import "google/protobuf/wrappers.proto";
 
 // Tests that wrapped values are supported as part of output message
diff --git a/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto b/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto
index c454691..2153ad5 100644
--- a/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto
+++ b/tests/inputs/googletypes_service_returns_empty/googletypes_service_returns_empty.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_service_returns_empty;
+
 import "google/protobuf/empty.proto";
 
 service Test {
diff --git a/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto b/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto
index 49b2a55..457707b 100644
--- a/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto
+++ b/tests/inputs/googletypes_service_returns_googletype/googletypes_service_returns_googletype.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_service_returns_googletype;
+
 import "google/protobuf/empty.proto";
 import "google/protobuf/struct.proto";
 
diff --git a/tests/inputs/googletypes_struct/googletypes_struct.proto b/tests/inputs/googletypes_struct/googletypes_struct.proto
index 1dbd64a..2b8b5c5 100644
--- a/tests/inputs/googletypes_struct/googletypes_struct.proto
+++ b/tests/inputs/googletypes_struct/googletypes_struct.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_struct;
+
 import "google/protobuf/struct.proto";
 
 message Test {
diff --git a/tests/inputs/googletypes_value/googletypes_value.proto b/tests/inputs/googletypes_value/googletypes_value.proto
index 379d336..d5089d5 100644
--- a/tests/inputs/googletypes_value/googletypes_value.proto
+++ b/tests/inputs/googletypes_value/googletypes_value.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package googletypes_value;
+
 import "google/protobuf/struct.proto";
 
 // Tests that fields of type google.protobuf.Value can contain arbitrary JSON-values.
diff --git a/tests/inputs/import_capitalized_package/capitalized.proto b/tests/inputs/import_capitalized_package/capitalized.proto
index 0b73bab..e80c95c 100644
--- a/tests/inputs/import_capitalized_package/capitalized.proto
+++ b/tests/inputs/import_capitalized_package/capitalized.proto
@@ -1,7 +1,7 @@
 syntax = "proto3";
 
 
-package Capitalized;
+package import_capitalized_package.Capitalized;
 
 message Message {
 
diff --git a/tests/inputs/import_capitalized_package/test.proto b/tests/inputs/import_capitalized_package/test.proto
index f94bbc9..38c9b2d 100644
--- a/tests/inputs/import_capitalized_package/test.proto
+++ b/tests/inputs/import_capitalized_package/test.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_capitalized_package;
+
 import "capitalized.proto";
 
 // Tests that we can import from a package with a capital name, that looks like a nested type, but isn't.
diff --git a/tests/inputs/import_child_package_from_package/child.proto b/tests/inputs/import_child_package_from_package/child.proto
index 0865fc8..d99c7c3 100644
--- a/tests/inputs/import_child_package_from_package/child.proto
+++ b/tests/inputs/import_child_package_from_package/child.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package package.childpackage;
+package import_child_package_from_package.package.childpackage;
 
 message ChildMessage {
 
diff --git a/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto b/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto
index 0d09132..66e0aa8 100644
--- a/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto
+++ b/tests/inputs/import_child_package_from_package/import_child_package_from_package.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_child_package_from_package;
+
 import "package_message.proto";
 
 // Tests generated imports when a message in a package refers to a message in a nested child package.
diff --git a/tests/inputs/import_child_package_from_package/package_message.proto b/tests/inputs/import_child_package_from_package/package_message.proto
index 943282c..79d66f3 100644
--- a/tests/inputs/import_child_package_from_package/package_message.proto
+++ b/tests/inputs/import_child_package_from_package/package_message.proto
@@ -2,7 +2,7 @@ syntax = "proto3";
 
 import "child.proto";
 
-package package;
+package import_child_package_from_package.package;
 
 message PackageMessage {
     package.childpackage.ChildMessage c = 1;
diff --git a/tests/inputs/import_child_package_from_root/child.proto b/tests/inputs/import_child_package_from_root/child.proto
index c874e14..2a46d5f 100644
--- a/tests/inputs/import_child_package_from_root/child.proto
+++ b/tests/inputs/import_child_package_from_root/child.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package childpackage;
+package import_child_package_from_root.childpackage;
 
 message Message {
 
diff --git a/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto b/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto
index d0c111f..6299831 100644
--- a/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto
+++ b/tests/inputs/import_child_package_from_root/import_child_package_from_root.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_child_package_from_root;
+
 import "child.proto";
 
 // Tests generated imports when a message in root refers to a message in a child package.
diff --git a/tests/inputs/import_circular_dependency/import_circular_dependency.proto b/tests/inputs/import_circular_dependency/import_circular_dependency.proto
index 7d02aad..8b159e2 100644
--- a/tests/inputs/import_circular_dependency/import_circular_dependency.proto
+++ b/tests/inputs/import_circular_dependency/import_circular_dependency.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_circular_dependency;
+
 import "root.proto";
 import "other.proto";
 
diff --git a/tests/inputs/import_circular_dependency/other.proto b/tests/inputs/import_circular_dependency/other.proto
index 2b936a9..833b869 100644
--- a/tests/inputs/import_circular_dependency/other.proto
+++ b/tests/inputs/import_circular_dependency/other.proto
@@ -1,7 +1,7 @@
 syntax = "proto3";
 
 import "root.proto";
-package other;
+package import_circular_dependency.other;
 
 message OtherPackageMessage {
     RootPackageMessage rootPackageMessage = 1;
diff --git a/tests/inputs/import_circular_dependency/root.proto b/tests/inputs/import_circular_dependency/root.proto
index 63d15bf..7383947 100644
--- a/tests/inputs/import_circular_dependency/root.proto
+++ b/tests/inputs/import_circular_dependency/root.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_circular_dependency;
+
 message RootPackageMessage {
 
 }
diff --git a/tests/inputs/import_cousin_package/cousin.proto b/tests/inputs/import_cousin_package/cousin.proto
index 4361545..2870dfe 100644
--- a/tests/inputs/import_cousin_package/cousin.proto
+++ b/tests/inputs/import_cousin_package/cousin.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package cousin.cousin_subpackage;
+package import_cousin_package.cousin.cousin_subpackage;
 
 message CousinMessage {
 }
diff --git a/tests/inputs/import_cousin_package/test.proto b/tests/inputs/import_cousin_package/test.proto
index 53f3b7f..89ec3d8 100644
--- a/tests/inputs/import_cousin_package/test.proto
+++ b/tests/inputs/import_cousin_package/test.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package test.subpackage;
+package import_cousin_package.test.subpackage;
 
 import "cousin.proto";
 
diff --git a/tests/inputs/import_cousin_package_same_name/cousin.proto b/tests/inputs/import_cousin_package_same_name/cousin.proto
index 9253b95..84b6a40 100644
--- a/tests/inputs/import_cousin_package_same_name/cousin.proto
+++ b/tests/inputs/import_cousin_package_same_name/cousin.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package cousin.subpackage;
+package import_cousin_package_same_name.cousin.subpackage;
 
 message CousinMessage {
 }
diff --git a/tests/inputs/import_cousin_package_same_name/test.proto b/tests/inputs/import_cousin_package_same_name/test.proto
index fe31b5f..7b420d3 100644
--- a/tests/inputs/import_cousin_package_same_name/test.proto
+++ b/tests/inputs/import_cousin_package_same_name/test.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package test.subpackage;
+package import_cousin_package_same_name.test.subpackage;
 
 import "cousin.proto";
 
diff --git a/tests/inputs/import_packages_same_name/import_packages_same_name.proto b/tests/inputs/import_packages_same_name/import_packages_same_name.proto
index c1f28e9..dff7efe 100644
--- a/tests/inputs/import_packages_same_name/import_packages_same_name.proto
+++ b/tests/inputs/import_packages_same_name/import_packages_same_name.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_packages_same_name;
+
 import "users_v1.proto";
 import "posts_v1.proto";
 
diff --git a/tests/inputs/import_packages_same_name/posts_v1.proto b/tests/inputs/import_packages_same_name/posts_v1.proto
index 506bf11..d3b9b1c 100644
--- a/tests/inputs/import_packages_same_name/posts_v1.proto
+++ b/tests/inputs/import_packages_same_name/posts_v1.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package posts.v1;
+package import_packages_same_name.posts.v1;
 
 message Post {
 
diff --git a/tests/inputs/import_packages_same_name/users_v1.proto b/tests/inputs/import_packages_same_name/users_v1.proto
index 6e46ba8..d3a17e9 100644
--- a/tests/inputs/import_packages_same_name/users_v1.proto
+++ b/tests/inputs/import_packages_same_name/users_v1.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package users.v1;
+package import_packages_same_name.users.v1;
 
 message User {
 
diff --git a/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto b/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto
index c43c1bc..edc4736 100644
--- a/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto
+++ b/tests/inputs/import_parent_package_from_child/import_parent_package_from_child.proto
@@ -2,7 +2,7 @@ syntax = "proto3";
 
 import "parent_package_message.proto";
 
-package parent.child;
+package import_parent_package_from_child.parent.child;
 
 // Tests generated imports when a message refers to a message defined in its parent package
 
diff --git a/tests/inputs/import_parent_package_from_child/parent_package_message.proto b/tests/inputs/import_parent_package_from_child/parent_package_message.proto
index cea3066..fb3fd31 100644
--- a/tests/inputs/import_parent_package_from_child/parent_package_message.proto
+++ b/tests/inputs/import_parent_package_from_child/parent_package_message.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package parent;
+package import_parent_package_from_child.parent;
 
 message ParentPackageMessage {
 }
diff --git a/tests/inputs/import_root_package_from_child/child.proto b/tests/inputs/import_root_package_from_child/child.proto
index d2b29cc..bd51967 100644
--- a/tests/inputs/import_root_package_from_child/child.proto
+++ b/tests/inputs/import_root_package_from_child/child.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package child;
+package import_root_package_from_child.child;
 
 import "root.proto";
 
diff --git a/tests/inputs/import_root_package_from_child/root.proto b/tests/inputs/import_root_package_from_child/root.proto
index 650b29b..6ae955a 100644
--- a/tests/inputs/import_root_package_from_child/root.proto
+++ b/tests/inputs/import_root_package_from_child/root.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_root_package_from_child;
+
 
 message RootMessage {
 }
diff --git a/tests/inputs/import_root_sibling/import_root_sibling.proto b/tests/inputs/import_root_sibling/import_root_sibling.proto
index 1d671b8..759e606 100644
--- a/tests/inputs/import_root_sibling/import_root_sibling.proto
+++ b/tests/inputs/import_root_sibling/import_root_sibling.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_root_sibling;
+
 import "sibling.proto";
 
 // Tests generated imports when a message in the root package refers to another message in the root package
diff --git a/tests/inputs/import_root_sibling/sibling.proto b/tests/inputs/import_root_sibling/sibling.proto
index 870baff..6b6ba2e 100644
--- a/tests/inputs/import_root_sibling/sibling.proto
+++ b/tests/inputs/import_root_sibling/sibling.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_root_sibling;
+
 message SiblingMessage {
 
 }
diff --git a/tests/inputs/import_service_input_message/child_package_request_message.proto b/tests/inputs/import_service_input_message/child_package_request_message.proto
index 6380db2..54fc112 100644
--- a/tests/inputs/import_service_input_message/child_package_request_message.proto
+++ b/tests/inputs/import_service_input_message/child_package_request_message.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package child;
+package import_service_input_message.child;
 
 message ChildRequestMessage {
     int32 child_argument = 1;
diff --git a/tests/inputs/import_service_input_message/import_service_input_message.proto b/tests/inputs/import_service_input_message/import_service_input_message.proto
index 7ca9c46..cbf48fa 100644
--- a/tests/inputs/import_service_input_message/import_service_input_message.proto
+++ b/tests/inputs/import_service_input_message/import_service_input_message.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_service_input_message;
+
 import "request_message.proto";
 import "child_package_request_message.proto";
 
diff --git a/tests/inputs/import_service_input_message/request_message.proto b/tests/inputs/import_service_input_message/request_message.proto
index 5bfceed..36a6e78 100644
--- a/tests/inputs/import_service_input_message/request_message.proto
+++ b/tests/inputs/import_service_input_message/request_message.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package import_service_input_message;
+
 message RequestMessage {
     int32 argument = 1;
 }
\ No newline at end of file
diff --git a/tests/inputs/int32/int32.proto b/tests/inputs/int32/int32.proto
index cae0dc7..4721c23 100644
--- a/tests/inputs/int32/int32.proto
+++ b/tests/inputs/int32/int32.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package int32;
+
 // Some documentation about the Test message.
 message Test {
     // Some documentation about the count.
diff --git a/tests/inputs/map/map.proto b/tests/inputs/map/map.proto
index 669e287..ecef3cc 100644
--- a/tests/inputs/map/map.proto
+++ b/tests/inputs/map/map.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package map;
+
 message Test {
     map<string, int32> counts = 1;
 }
diff --git a/tests/inputs/mapmessage/mapmessage.proto b/tests/inputs/mapmessage/mapmessage.proto
index 07dcce5..2c704a4 100644
--- a/tests/inputs/mapmessage/mapmessage.proto
+++ b/tests/inputs/mapmessage/mapmessage.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package mapmessage;
+
 message Test {
   map<string, Nested> items = 1;
 }
diff --git a/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto b/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto
index 636bb55..71cb029 100644
--- a/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto
+++ b/tests/inputs/namespace_builtin_types/namespace_builtin_types.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package namespace_builtin_types;
+
 // Tests that messages may contain fields with names that are python types
 
 message Test {
diff --git a/tests/inputs/namespace_keywords/namespace_keywords.proto b/tests/inputs/namespace_keywords/namespace_keywords.proto
index 6d1a7c5..ac3e5c5 100644
--- a/tests/inputs/namespace_keywords/namespace_keywords.proto
+++ b/tests/inputs/namespace_keywords/namespace_keywords.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package namespace_keywords;
+
 // Tests that messages may contain fields that are Python keywords
 //
 // Generated with Python 3.7.6
diff --git a/tests/inputs/nested/nested.proto b/tests/inputs/nested/nested.proto
index 98bafd9..043cee0 100644
--- a/tests/inputs/nested/nested.proto
+++ b/tests/inputs/nested/nested.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package nested;
+
 // A test message with a nested message inside of it.
 message Test {
     // This is the nested type.
diff --git a/tests/inputs/nested2/nested2.proto b/tests/inputs/nested2/nested2.proto
index 3e39918..cd6510c 100644
--- a/tests/inputs/nested2/nested2.proto
+++ b/tests/inputs/nested2/nested2.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package nested2;
+
 import "package.proto";
 
 message Game {
diff --git a/tests/inputs/nested2/package.proto b/tests/inputs/nested2/package.proto
index 4466256..e12abb1 100644
--- a/tests/inputs/nested2/package.proto
+++ b/tests/inputs/nested2/package.proto
@@ -1,6 +1,6 @@
 syntax = "proto3";
 
-package equipment;
+package nested2.equipment;
 
 message Weapon {
 
diff --git a/tests/inputs/nestedtwice/nestedtwice.proto b/tests/inputs/nestedtwice/nestedtwice.proto
index 7e9c206..9a54a86 100644
--- a/tests/inputs/nestedtwice/nestedtwice.proto
+++ b/tests/inputs/nestedtwice/nestedtwice.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package nestedtwice;
+
 message Test {
   message Top {
     message Middle {
diff --git a/tests/inputs/oneof/oneof.proto b/tests/inputs/oneof/oneof.proto
index 1f9c4b2..21aa6c6 100644
--- a/tests/inputs/oneof/oneof.proto
+++ b/tests/inputs/oneof/oneof.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package oneof;
+
 message Test {
   oneof foo {
     int32 pitied = 1;
diff --git a/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto b/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto
index 44163c7..f7ac6fe 100644
--- a/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto
+++ b/tests/inputs/oneof_default_value_serialization/oneof_default_value_serialization.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package oneof_default_value_serialization;
+
 import "google/protobuf/duration.proto";
 import "google/protobuf/timestamp.proto";
 import "google/protobuf/wrappers.proto";
diff --git a/tests/inputs/oneof_empty/oneof_empty.proto b/tests/inputs/oneof_empty/oneof_empty.proto
index 45ca371..ca51d5a 100644
--- a/tests/inputs/oneof_empty/oneof_empty.proto
+++ b/tests/inputs/oneof_empty/oneof_empty.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package oneof_empty;
+
 message Nothing {}
 
 message MaybeNothing {
diff --git a/tests/inputs/oneof_enum/oneof_enum.proto b/tests/inputs/oneof_enum/oneof_enum.proto
index dfe19d4..906abcb 100644
--- a/tests/inputs/oneof_enum/oneof_enum.proto
+++ b/tests/inputs/oneof_enum/oneof_enum.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package oneof_enum;
+
 message Test {
   oneof action {
     Signal signal = 1;
diff --git a/tests/inputs/proto3_field_presence/proto3_field_presence.proto b/tests/inputs/proto3_field_presence/proto3_field_presence.proto
index d647843..f28123d 100644
--- a/tests/inputs/proto3_field_presence/proto3_field_presence.proto
+++ b/tests/inputs/proto3_field_presence/proto3_field_presence.proto
@@ -1,3 +1,5 @@
 syntax = "proto3";
 
+package proto3_field_presence;
+
 message InnerTest {
diff --git a/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto
index c4dc9d4..caa76ec 100644
--- a/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto
+++ b/tests/inputs/proto3_field_presence_oneof/proto3_field_presence_oneof.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package proto3_field_presence_oneof;
+
 message Test {
     oneof kind {
         Nested nested = 1;
diff --git a/tests/inputs/recursivemessage/recursivemessage.proto b/tests/inputs/recursivemessage/recursivemessage.proto
index f988316..1da2b57 100644
--- a/tests/inputs/recursivemessage/recursivemessage.proto
+++ b/tests/inputs/recursivemessage/recursivemessage.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package recursivemessage;
+
 message Test {
     string name = 1;
     Test child = 2;
diff --git a/tests/inputs/ref/ref.proto b/tests/inputs/ref/ref.proto
index e09fb15..6945590 100644
--- a/tests/inputs/ref/ref.proto
+++ b/tests/inputs/ref/ref.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package ref;
+
 import "repeatedmessage.proto";
 
 message Test {
diff --git a/tests/inputs/repeated/repeated.proto b/tests/inputs/repeated/repeated.proto
index 42c1132..4f3c788 100644
--- a/tests/inputs/repeated/repeated.proto
+++ b/tests/inputs/repeated/repeated.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package repeated;
+
 message Test {
     repeated string names = 1;
 }
diff --git a/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto
index 7b7bf36..38f1eaa 100644
--- a/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto
+++ b/tests/inputs/repeated_duration_timestamp/repeated_duration_timestamp.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package repeated_duration_timestamp;
+
 import "google/protobuf/duration.proto";
 import "google/protobuf/timestamp.proto";
 
diff --git a/tests/inputs/repeatedpacked/repeatedpacked.proto b/tests/inputs/repeatedpacked/repeatedpacked.proto
index ea86dde..a037d1b 100644
--- a/tests/inputs/repeatedpacked/repeatedpacked.proto
+++ b/tests/inputs/repeatedpacked/repeatedpacked.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package repeatedpacked;
+
 message Test {
     repeated int32 counts = 1;
     repeated sint64 signed = 2;
diff --git a/tests/inputs/service_separate_packages/messages.proto b/tests/inputs/service_separate_packages/messages.proto
index add0ed8..270b188 100644
--- a/tests/inputs/service_separate_packages/messages.proto
+++ b/tests/inputs/service_separate_packages/messages.proto
@@ -3,7 +3,7 @@ syntax = "proto3";
 import "google/protobuf/duration.proto";
 import "google/protobuf/timestamp.proto";
 
-package things.messages;
+package service_separate_packages.things.messages;
 
 message DoThingRequest {
   string name = 1;
diff --git a/tests/inputs/service_separate_packages/service.proto b/tests/inputs/service_separate_packages/service.proto
index 48acc25..950eab4 100644
--- a/tests/inputs/service_separate_packages/service.proto
+++ b/tests/inputs/service_separate_packages/service.proto
@@ -2,7 +2,7 @@ syntax = "proto3";
 
 import "messages.proto";
 
-package things.service;
+package service_separate_packages.things.service;
 
 service Test {
   rpc DoThing (things.messages.DoThingRequest) returns (things.messages.DoThingResponse);
diff --git a/tests/inputs/signed/signed.proto b/tests/inputs/signed/signed.proto
index 23fc9ee..b40aad4 100644
--- a/tests/inputs/signed/signed.proto
+++ b/tests/inputs/signed/signed.proto
@@ -1,5 +1,7 @@
 syntax = "proto3";
 
+package signed;
+
 message Test {
     // todo: rename fields after fixing bug where 'signed_32_positive' will map to 'signed_32Positive' as output json
     sint32 signed32 = 1;    //  signed_32_positive
diff --git a/tests/test_features.py b/tests/test_features.py
index 0fedce2..7dc3f35 100644
--- a/tests/test_features.py
+++ b/tests/test_features.py
@@ -480,7 +480,7 @@ def test_iso_datetime_list():
 
 
 def test_enum_service_argument__expected_default_value():
-    from tests.output_betterproto.service.service import ThingType, TestStub
+    from tests.output_betterproto.service import ThingType, TestStub
 
     sig = signature(TestStub.do_thing)
     assert sig.parameters["type"].default == ThingType.UNKNOWN
diff --git a/tests/test_inputs.py b/tests/test_inputs.py
index dbcf197..278a4da 100644
--- a/tests/test_inputs.py
+++ b/tests/test_inputs.py
@@ -23,8 +23,6 @@ from tests.util import (
 # break things because we can't properly reset the symbol database.
 os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
 
-from google.protobuf import symbol_database
-from google.protobuf.descriptor_pool import DescriptorPool
 from google.protobuf.json_format import Parse
 
 
@@ -125,14 +123,9 @@ def dict_replace_nans(input_dict: Dict[Any, Any]) -> Dict[Any, Any]:
 
 
 @pytest.fixture
-def test_data(request):
+def test_data(request, reset_sys_path):
     test_case_name = request.param
 
-    # Reset the internal symbol database so we can import the `Test` message
-    # multiple times. Ugh.
-    sym = symbol_database.Default()
-    sym.pool = DescriptorPool()
-
     reference_module_root = os.path.join(
         *reference_output_package.split("."), test_case_name
     )
@@ -158,8 +151,6 @@ def test_data(request):
         )
     )
 
-    sys.path.remove(reference_module_root)
-
 
 @pytest.mark.parametrize("test_data", test_cases.messages, indirect=True)
 def test_message_can_instantiated(test_data: TestData) -> None:
-- 
2.40.0

