Skip to main content

nose-seed-faker

A nose plugin for seeding the faker package based on test names.

$ nosetests --with-seed-faker mytests/

Faker is seeded at the beginning of each test based on the test name, so each test that uses faker will use the same fake data between test runs, regardless of test order.

This relies on the behavior that faker seeds a instance of random that is shared globally across instances of the Faker class, so seeding any instance of Faker will seed every instance of Faker.

For example, these two tests use faker to generate fake email addresses:

import unittest

from faker import Faker

fake = Faker()


class TestEmail(unittest.TestCase):
    def test_one(self):
        email = fake.email()
        print(email)

    def test_two(self):
        email = fake.email()
        print(email)

Since faker generates random email addresses, if we run test_one multiple times, we’ll use different emails for each test run:

$ nosetests -v --nocapture tests.py:TestEmail.test_one tests.py:TestEmail.test_one
test_one (tests.TestEmail) ... opouros@hermistondeckow.com
ok
test_one (tests.TestEmail) ... sgrady@hotmail.com
ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

While this is good for increasing the surface area of emails we use in our tests, it can cause flaky tests – a test could mysteriously fail, but if you tried running it again to debug the failure, all of a sudden it’s passing again!

nose-seed-faker solves this problem by seeding faker based on the name of each test. Using the plugin, if you run the same test multiple times, it’ll use the same email address:

$ nosetests --with-seed-faker -v --nocapture tests.py:TestEmail.test_one tests.py:TestEmail.test_one
test_one (tests.TestEmail) ... mitchel07@yost.com
ok
test_one (tests.TestEmail) ... mitchel07@yost.com
ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

Each individual test will use a different email, so we still get a good surface area of emails to use in our tests:

$ nosetests --with-seed-faker -v --nocapture tests.py
test_one (tests.TestEmail) ... mitchel07@yost.com
ok
test_two (tests.TestEmail) ... kurt.bartell@yahoo.com
ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

Installation

$ pip install nose-seed-faker

Warning

Versions 0.5.2 and lower of faker will seed the random module globally.

Version 0.5.3 fixes this issue by seeding an instance of the random.Random class, but at the time of this writing, this fix hasn’t been released to PyPI yet.

Until version 0.5.3 is released on PyPI, you can install it like so:

$ pip install git+http://github.com/joke2k/faker.git@dabf922af72783ebd9d163611ab0f4f307156443#egg=fake-factory==0.5.3

History

0.1.2

released 2015-06-30

  • initial release

Metadata

Release files for nose-seed-faker 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nose-seed-faker 0.1.2
File Size Uploaded Provenance Actions
nose-seed-faker-0.1.2.tar.gz 4.1 kB Without provenance Details for nose-seed-faker-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nose-seed-faker 0.1.2
File Interpreter ABI Platform Actions
nose-seed-faker-0.1.2.macosx-10.9-x86_64.exe Details for nose-seed-faker-0.1.2.macosx-10.9-x86_64.exe

Total release size: 73.7 kB

Release files / nose-seed-faker-0.1.2.tar.gz

Download URL nose-seed-faker-0.1.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5721afc2838c478ae5ad8550d3716353bfd4cc7f10a71f5214c9ccc53ed78a5e
BLAKE2b-256 checksum
How to use checksums
46948cbe8d992d54059be6ab5e99fb77970159e3a5ea450a7a7d28f5f200cc17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nose-seed-faker-0.1.2.macosx-10.9-x86_64.exe

Download URL nose-seed-faker-0.1.2.macosx-10.9-x86_64.exe
Size 69.6 kB
Tags Source
SHA-256 checksum
How to use checksums
89f2be74076d106b7403472ac238202da0b1e272656acf2fc36e8a47280b1231
BLAKE2b-256 checksum
How to use checksums
13726a5d025d60e91f2b6a814d9e18942afa31e472de3a3853ed2144c13b0ed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for nose-seed-faker 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

0.1.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page