pytest_unique package

Submodules

pytest_unique.count module

Counters for iterating over evenly spaced values.

Here is an example of using an in-memory counter:

>>> counter = memory_count(10, step=2)
>>> next(counter)
10
>>> next(counter)
12
pytest_unique.count.file_count(countfile, start=0, step=1)

In-file counter.

Parameters:
  • countfile – Path to count file for persistence.

  • start – Optional first count, defaults to 0.

  • step – Optional increment between counts, defaults to 1.

Raises:

ValueError – On next() when the countfile doesn’t contain a count.

pytest_unique.count.memory_count(start=0, step=1)

In-memory counter.

Parameters:
  • start – Optional first count, defaults to 0.

  • step – Optional increment between counts, defaults to 1.

pytest_unique.fixtures module

Unique fixture.

pytest_unique.fixtures.unique(request)

File backed unique.

pytest_unique.fixtures.unique_in_file(request)

File backed unique.

pytest_unique.fixtures.unique_in_memory()

Memory backed unique.

pytest_unique.lock module

Locks.

exception pytest_unique.lock.AlreadyLockedError

Bases: Exception

Raised when a lock was already acquired.

class pytest_unique.lock.BaseLock

Bases: object

Base class for locks.

abstract property is_locked

Return True if lock acquired, False otherwise.

abstract lock()

Acquire the lock.

Raises:

AlreadyLockedError – If the lock was already acquired.

abstract unlock()

Release the lock.

Raises:

NotLockedError – If the lock was never acquired or already released.

class pytest_unique.lock.FileLock(lockfile, lockfd=None)

Bases: BaseLock

Advisory file locking.

Parameters:

lockfile – Path to the lock file.

property is_locked

Check if the file is locked, based on the file descriptor.

lock()

See BaseLock.lock.

unlock()

See BaseLock.unlock.

class pytest_unique.lock.MemoryLock(is_locked=False)

Bases: BaseLock

In-memory locking.

property is_locked

Accessor for read-only private field.

lock()

See BaseLock.lock.

unlock()

See BaseLock.unlock.

exception pytest_unique.lock.NotLockedError

Bases: Exception

Raised when the lock was never acquired or already released.

class pytest_unique.lock.NullLock

Bases: BaseLock

Null pattern implementation.

property is_locked

Return False.

lock()

Do nothing.

unlock()

Do nothing.

pytest_unique.lock.lock(fd)
pytest_unique.lock.unlock(fd)

pytest_unique.registry module

Entry points based registry management.

pytest_unique.registry.get_entry_points(group)

Get the list of pytest_unique entry points.

pytest_unique.registry.registry_add(group, name, entry, registry=None)

Add an entry to a registry.

Parameters:
  • group – Group of the entry.

  • name – Name of the entry.

  • entry – Entry to add.

  • registry – Optional registry to update.

Returns:

A registry with the entry.

pytest_unique.registry.registry_get(group, name, registry=None)

Get an entry from a registry.

If the registry is not defined or the group is not in the registry, the registry is loaded again.

Parameters:
  • group – Group of the entry.

  • name – Name of the entry.

  • registry – Optional registry to get from.

Raises:

KeyError – If not found.

pytest_unique.registry.registry_load(group, registry=None)

Find all installed entry points.

pytest_unique.registry.registry_remove(group, name, registry=None)

Remove an entry from a registry.

If the entry doesn’t exist, return silently.

Parameters:
  • group – Group of the entry.

  • name – Name of the entry.

  • registry – Optional registry to update.

pytest_unique.unique module

Unique data generation.

class pytest_unique.unique.Unique(count=NOTHING, registry=NOTHING)

Bases: object

Generate data using plugins.

Plugins are read from the pytest_unique entrypoints.

count
get_plugin(_name, *args, **kwargs)

Find plugin in the registry.

registry
pytest_unique.unique.count_factory()

Create a counter that increases with each unique call.

pytest_unique.unique.unique_bytes(unique)

Return bytes unique to this factory instance.

pytest_unique.unique.unique_digits(unique, *args, **kwargs)

Return digits unique to this factory instance.

Takes the same arguments as integer.

pytest_unique.unique.unique_email(unique, *args, **kwargs)

Return an email unique to this factory instance.

Takes the same arguments as text.

pytest_unique.unique.unique_float(unique)

Return a float unique to this factory instance.

The floating point number by making an integer for the whole part and another integer for the decimal part.

pytest_unique.unique.unique_integer(unique, base=None, mod=None)

Return an integer unique to this factory instance.

Parameters:
  • base – Optional base to add to the integer.

  • mod – Optional modulo to apply on the integer.

pytest_unique.unique.unique_password(unique, lowercase=4, uppercase=2, digits=1, punctuation=1)

Return a password unique to this factory instance.

Parameters:
  • lowercase – Number of lowercase letters, defaults to 4.

  • uppercase – Number of uppercase letters, defaults to 2.

  • digits – Number of digits, defaults to 1.

  • punctuation – Number of punctuation characters, defaults to 1.

pytest_unique.unique.unique_text(unique, prefix=None, suffix=None, separator='-', limit=None)

Return text unique to this factory instance.

Parameters:
  • prefix – Used as a prefix for the unique string, defaults to a generated string from the stack frame.

  • suffix – Optional suffix for the unique string.

  • separator – Separator between parts of the string, defaults to ‘-‘.

  • limit – Optional limit for the unique string.

pytest_unique.unique.unique_uuid(unique, integer=None)

Return a UUID unique to this factory instance.

This method provides a more predictable alternative to uuid4().

Module contents