[Python] Pybandit to allow B311: pseudo-random generators to be used in tests

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I've used random.choice for tests. And Bandit is showing warnings.

    x = random.choice(lists)


    I know I could use # nosec comment to suppress the warning. But it would be inconvinent to do it in all lines

    x = random.choice(lists) # nosec


    I want to allow random for file with tests_*.py using .bandit configuration files. I've found from other samples that you can do it for things like asserts like:

    .bandit

    assert_used:
    skips: ['test.py$', '^test_*.py']


    So is there any way for B311 ?

    Continue reading...

Compartilhe esta Página