Repository: joke2k/faker

Issue:
Can we have a "non formatted" postcode for pt_BR localization?
* Faker version: 3.0.0
* OS: Windows 10 pro (x64)

I'm using Faker to generate postcode using the pt_BR localization. The example on [`address` section](https://faker.readthedocs.io/en/latest/locales/pt_BR.html#faker-providers-address) shows a numeric sequence containing 8 numbers and that was what I expect.

```python
fake.postcode()
# '35285968'
```

Anyway, I'm getting some problems in my tests because the output of this function sometimes returns a formatted postcode. Example:

```python
fake.postcode()
# '35285968'    -- cool :D

fake.postcode()
# '35285-968'    -- sad :(
```

### Expected behavior

I would like to generate postcode exactly hows the documentation says, just numbers, without any formatting. As a temporary solution, I'm using a `replace` to remove any `-` present, but I would like to have a cleaner solution using just Faker. Maybe this "formatted" version can be specified by an argument in the `postcode` function. 

### Actual behavior

Getting a non deterministic postcode, I don't know which type of postalcode format I will get.

Discussion:

Patch:
diff --git a/faker/providers/address/pt_BR/__init__.py b/faker/providers/address/pt_BR/__init__.py
index dacd633f..8b524801 100644
--- a/faker/providers/address/pt_BR/__init__.py
+++ b/faker/providers/address/pt_BR/__init__.py
@@ -99,7 +99,8 @@ class Provider(AddressProvider):
 
     building_number_formats = ('%', '%#', '%#', '%#', '%##')
 
-    postcode_formats = ('########', '#####-###')
+    postcode_raw_formats = ('########', )
+    postcode_all_formats = postcode_raw_formats + ('#####-###', )
 
     bairros = (
         'Aarão Reis', 'Acaba Mundo', 'Acaiaca', 'Ademar Maldonado', 'Aeroporto', 'Aguas Claras', 'Alípio De Melo',
@@ -296,6 +297,16 @@ class Provider(AddressProvider):
         """
         return self.random_element(self.bairros)
 
+    def postcode(self, formatted=True):
+        """
+        Randomly returns a postcode.
+        :param formatted: True to allow formatted postcodes, else False (default True)
+        :example formatted: '41224-212' '83992-291' '12324322'
+        :example raw: '43920231' '34239530'
+        """
+        template = self.postcode_all_formats if formatted else self.postcode_raw_formats
+        return self.bothify(self.random_element(template))
+
     # aliases
     def neighborhood(self):
         return self.bairro()


Test patch:
diff --git a/tests/providers/test_address.py b/tests/providers/test_address.py
index 4e3c889f..66114721 100644
--- a/tests/providers/test_address.py
+++ b/tests/providers/test_address.py
@@ -1029,6 +1029,18 @@ class TestPtBr(unittest.TestCase):
         address = self.fake.address()
         assert isinstance(address, str)
 
+    def test_raw_postcode(self):
+        for _ in range(100):
+            postcode = self.fake.postcode(formatted=False)
+            assert isinstance(postcode, str)
+            assert re.match(r'^\d{8}$', postcode)
+
+    def test_formatted_postcode(self):
+        for _ in range(100):
+            postcode = self.fake.postcode()
+            assert isinstance(postcode, str)
+            assert re.match(r'^\d{5}-?\d{3}$', postcode)
+
 
 class TestPtPT(unittest.TestCase):
 
diff --git a/tests/providers/test_person.py b/tests/providers/test_person.py
index dfc314fd..cbcb28bf 100644
--- a/tests/providers/test_person.py
+++ b/tests/providers/test_person.py
@@ -252,7 +252,7 @@ class TestPlPL(unittest.TestCase):
     @staticmethod
     def validate_nip(nip_str):
         """
-        Validates NIP using recomended code
+        Validates NIP using recommended code
         https://pl.wikibooks.org/wiki/Kody_%C5%BAr%C3%B3d%C5%82owe/Implementacja_NIP
         """
         nip_str = nip_str.replace('-', '')