Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] test failures with non-standard terminal width #342

Closed
lmontrieux opened this issue Mar 25, 2023 · 4 comments
Closed

[BUG] test failures with non-standard terminal width #342

lmontrieux opened this issue Mar 25, 2023 · 4 comments
Labels
bug Something isn't working CI Issue is related to CI stale No activity in a long time

Comments

@lmontrieux
Copy link
Contributor

Describe the issue:

When running the full test suite using python -m pytest, failures may happen in the docs/examples/basics.rst test suite if the terminal width is not 80 columns.

The issue seems to be with tables, where python only displays a subset of the columns to fit the terminal width. A larger terminal produces more columns, and therefore deviates from the expected result.
Similarly, a narrower terminal produces less columns, which also deviates from the expected result.

Reproduce the code example:

* Run `python -m pytest` in a standard, 80-col terminal window. Tests pass
* Run the same command in a 120-col terminal window (for example). Tests fail.

Error message:

============================================================================= FAILURES =============================================================================
_______________________________________________________________________ [doctest] basics.rst _______________________________________________________________________
205 this session. For this, it is first necessary to call
206 :func:`Session.load <fastf1.core.Session.load>`. This will load all available data for the
207 session from various APIs. Downloading and processing of the data may take a
208 few seconds. It is highly recommended to utilize FastF1's builtin caching
209 functionality to speed up data loading and to prevent excessive API requests.
210
211   >>> fastf1.Cache.enable_cache("path/to/empty/folder")  # doctest: +SKIP
212   >>> session = fastf1.get_session(2021, 'French Grand Prix', 'Q')
213   >>> session.load()
214   >>> session.results
Differences (unified diff with -expected +actual):
    @@ -1,23 +1,23 @@
    -   DriverNumber BroadcastName Abbreviation  ... Time Status Points
    -33           33  M VERSTAPPEN          VER  ...  NaT           NaN
    -44           44    L HAMILTON          HAM  ...  NaT           NaN
    -77           77      V BOTTAS          BOT  ...  NaT           NaN
    -11           11       S PEREZ          PER  ...  NaT           NaN
    -55           55       C SAINZ          SAI  ...  NaT           NaN
    -10           10       P GASLY          GAS  ...  NaT           NaN
    -16           16     C LECLERC          LEC  ...  NaT           NaN
    -4             4      L NORRIS          NOR  ...  NaT           NaN
    -14           14      F ALONSO          ALO  ...  NaT           NaN
    -3             3   D RICCIARDO          RIC  ...  NaT           NaN
    -31           31        E OCON          OCO  ...  NaT           NaN
    -5             5      S VETTEL          VET  ...  NaT           NaN
    -99           99  A GIOVINAZZI          GIO  ...  NaT           NaN
    -63           63     G RUSSELL          RUS  ...  NaT           NaN
    -47           47  M SCHUMACHER          MSC  ...  NaT           NaN
    -6             6      N LATIFI          LAT  ...  NaT           NaN
    -7             7   K RAIKKONEN          RAI  ...  NaT           NaN
    -9             9     N MAZEPIN          MAZ  ...  NaT           NaN
    -18           18      L STROLL          STR  ...  NaT           NaN
    -22           22     Y TSUNODA          TSU  ...  NaT           NaN
    +   DriverNumber BroadcastName Abbreviation           TeamName TeamColor  ...                     Q2                     Q3 Time  Status  Points
    +33           33  M VERSTAPPEN          VER    Red Bull Racing    0600EF  ... 0 days 00:01:31.080000 0 days 00:01:29.990000  NaT             NaN
    +44           44    L HAMILTON          HAM           Mercedes    00D2BE  ... 0 days 00:01:30.788000 0 days 00:01:30.248000  NaT             NaN
    +77           77      V BOTTAS          BOT           Mercedes    00D2BE  ... 0 days 00:01:30.735000 0 days 00:01:30.376000  NaT             NaN
    +11           11       S PEREZ          PER    Red Bull Racing    0600EF  ... 0 days 00:01:30.971000 0 days 00:01:30.445000  NaT             NaN
    +55           55       C SAINZ          SAI            Ferrari    DC0004  ... 0 days 00:01:31.146000 0 days 00:01:30.840000  NaT             NaN
    +10           10       P GASLY          GAS         AlphaTauri    2B4562  ... 0 days 00:01:31.353000 0 days 00:01:30.868000  NaT             NaN
    +16           16     C LECLERC          LEC            Ferrari    DC0004  ... 0 days 00:01:31.567000 0 days 00:01:30.987000  NaT             NaN
    +4             4      L NORRIS          NOR            McLaren    FF9800  ... 0 days 00:01:31.542000 0 days 00:01:31.252000  NaT             NaN
    +14           14      F ALONSO          ALO             Alpine    0090FF  ... 0 days 00:01:31.549000 0 days 00:01:31.340000  NaT             NaN
    +3             3   D RICCIARDO          RIC            McLaren    FF9800  ... 0 days 00:01:31.615000 0 days 00:01:31.382000  NaT             NaN
    +31           31        E OCON          OCO             Alpine    0090FF  ... 0 days 00:01:31.736000                    NaT  NaT             NaN
    +5             5      S VETTEL          VET       Aston Martin    006F62  ... 0 days 00:01:31.767000                    NaT  NaT             NaN
    +99           99  A GIOVINAZZI          GIO  Alfa Romeo Racing    900000  ... 0 days 00:01:31.813000                    NaT  NaT             NaN
    +63           63     G RUSSELL          RUS           Williams    005AFF  ... 0 days 00:01:32.065000                    NaT  NaT             NaN
    +47           47  M SCHUMACHER          MSC       Haas F1 Team    FFFFFF  ...                    NaT                    NaT  NaT             NaN
    +6             6      N LATIFI          LAT           Williams    005AFF  ...                    NaT                    NaT  NaT             NaN
    +7             7   K RAIKKONEN          RAI  Alfa Romeo Racing    900000  ...                    NaT                    NaT  NaT             NaN
    +9             9     N MAZEPIN          MAZ       Haas F1 Team    FFFFFF  ...                    NaT                    NaT  NaT             NaN
    +18           18      L STROLL          STR       Aston Martin    006F62  ...                    NaT                    NaT  NaT             NaN
    +22           22     Y TSUNODA          TSU         AlphaTauri    2B4562  ...                    NaT                    NaT  NaT             NaN
     <BLANKLINE>
     [20 rows x 16 columns]
@theOehrly
Copy link
Owner

Yes, I know about this one. I have already wasted a considerable amount of time with this, but without reasonable success.
In theory, pandas has settings for this to set a fixed with. In practice, they don't seem to work with pytest. I tried figuring out from pandas' own test setup but failed because it is way more complex. Generally, people running doctests on DataFrames are a bit sparse, so there's not that much information out there, it seems.
At some point I just settled with "works in CI" and "works in PyCharm's default console" i. e. I can run tests locally and get the same result as the CI. Not many people are actually trying to run the test suit for FastF1. And at some point the amount of time I started wasting on this was not justifiable.

If someone can find a reliable fix for this, I'll be very happy.

@theOehrly theOehrly added bug Something isn't working CI Issue is related to CI labels Mar 25, 2023
@harningle
Copy link
Contributor

Seems related to this: pytest-dev/pytest#4030?

@theOehrly
Copy link
Owner

Looks somewhat promising. I don't think I've tried an autouse fixture before but I'm not sure. I still haven't fully understood how pytest interacts with modules like doctest. I'll give it a try.

@theOehrly
Copy link
Owner

@lmontrieux Is this still an issue? What terminal were you using to get the test failures?

I just tried:

  • Windows CMD
  • Windows Terminal (new app)
  • PyCharm (on Windows) builtin terminal
  • WSL Ubuntu
  • Docker python:3.10
  • Docker debian:latest

I'm running out of ideas for test environments that I can quickly set up 😅 Can you tell me what I need to do to get these tests to fail?

@theOehrly theOehrly added the stale No activity in a long time label Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CI Issue is related to CI stale No activity in a long time
Projects
None yet
Development

No branches or pull requests

3 participants