[issue45827] Unittest - commenting passing tests cause previous failing tests to pass

2021-11-16 Thread Guido van Rossum


Change by Guido van Rossum :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45827] Unittest - commenting passing tests cause previous failing tests to pass

2021-11-16 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

At a quick glance, I am 95% sure the problem lies in these two snippets of your 
code, not unittest:

class My_Time:
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]


if is_leapyr(year):
my_time.months[1] = 29


The first snippet makes months, a mutable list, a class attribute, which means 
it is shared by all instances of the class. The second snippet mutates that 
list, which means every single instance will see the same value.

So commenting out some tests will change whether or not the shared list gets 
mutated, which will change whether or not other tests pass or fail.

I think the smallest change you need make to fix your code is to put the 
initialisation of My_Time into an `__init__` method, so that the attributes 
(including the list) are no longer shared between all instances.

class My_Time:
def __init__(self):
...

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45827] Unittest - commenting passing tests cause previous failing tests to pass

2021-11-16 Thread Jamie Chaisson


New submission from Jamie Chaisson :

Ubuntu Release 20.04.3 LTS (Focal Fossa) 64-bit
Using unittest, testing with assertEqual on int values and known good output. 
Unittest produces one-off error on handful of edge-case tests causing assert to 
fail. Commenting out passing assertEquals tests to isolate failing tests causes 
previous failing tests to pass (reproducible). All input values produce output 
values when testing by hand, only different when using unittest.

Pardon the homework. Removing the class and moving member variables into 
my_datetime function resolves the issue; however, the behavior as written 
should not be happening.

--
components: Tests
files: tests.py
messages: 406449
nosy: nuse
priority: normal
severity: normal
status: open
title: Unittest - commenting passing tests cause previous failing tests to pass
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file50446/tests.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com